[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

custom attribute accessors ?

konsu

1/7/2006 2:14:00 AM

hello,

i need to define a number of custom attribute readers on my class. so
far i have come up with two ways to do it. the code below is a
simplified version. but i cannot decide which one is "preferable". whis
one would the experts use? why?

thanks
konstantin

class A
[:nameof].each { |x| module_eval "def #{x}() @#{x} end" }
def initialize() @nameof = self.class.to_s end
end

class B
[:nameof].each { |x| define_method(x) {
instance_variable_get("@#{x}") } }
def initialize() @nameof = self.class.to_s end
end

5 Answers

ES

1/7/2006 9:28:00 AM

0

On 2006.01.07 17:13, ako... wrote:
> hello,
>
> i need to define a number of custom attribute readers on my class. so
> far i have come up with two ways to do it. the code below is a
> simplified version. but i cannot decide which one is "preferable". whis
> one would the experts use? why?
>
> thanks
> konstantin
>
> class A
> [:nameof].each { |x| module_eval "def #{x}() @#{x} end" }
> def initialize() @nameof = self.class.to_s end
> end
>
> class B
> [:nameof].each { |x| define_method(x) {
> instance_variable_get("@#{x}") } }
> def initialize() @nameof = self.class.to_s end
> end

Hm, by your examples it would seem to be OK to
use the standard attr_* methods:

class A
# Symbol or String
[...].each {|attribute| attr_reader attribute}
end

Or did I incorrectly understand what you needed?


E


nospam

6/9/2009 12:24:00 PM

0

On Tue, 9 Jun 2009 08:18:07 -0400, "Mr Wonderful"
<mrwonderful@wtbtrainingacademy.com> wrote:

>
>"Vladimir Tschenko" <nospam@here.org> wrote in message
>news:4a2d69f6.29921234@news.datemas.de...
>> On Mon, 08 Jun 2009 13:31:07 -0600, rightwing@ignorant.com wrote:
>>
>>>On Mon, 08 Jun 2009 14:51:10 GMT, nospam@here.org
>>>(Vladimir Tschenko) wrote:
>>>
>>>>>>Obama's Enemies List Grows
>>>>>
>>>>>Well, fortunately, they've caught one of you,
>>>>>WaybackWhacko.
>>>>>
>>>>Absence of refutation noted.
>>>
>>>Well, they did
>>>
>>>That's why your racist scumbag is whining.
>>
>> Your mother only fucked three white guys, so it shouldn't be too hard
>> to find the identity of your father.
>A USELESS INSULT FROM A USELESS WHITE TRASH BASTARD!
>
Hey, it's the affirmative action boy.

Long time, no see.

rightwing

6/9/2009 2:41:00 PM

0

On Tue, 9 Jun 2009 08:18:07 -0400, "Mr Wonderful"
<mrwonderful@wtbtrainingacademy.com> wrote:

>
>"Vladimir Tschenko" <nospam@here.org> wrote in message
>news:4a2d69f6.29921234@news.datemas.de...
>> On Mon, 08 Jun 2009 13:31:07 -0600, rightwing@ignorant.com wrote:
>>
>>>On Mon, 08 Jun 2009 14:51:10 GMT, nospam@here.org
>>>(Vladimir Tschenko) wrote:
>>>
>>>>>>Obama's Enemies List Grows
>>>>>
>>>>>Well, fortunately, they've caught one of you,
>>>>>WaybackWhacko.
>>>>>
>>>>Absence of refutation noted.
>>>
>>>Well, they did
>>>
>>>That's why your racist scumbag is whining.
>>
>> Your mother only fucked three white guys, so it shouldn't be too hard
>> to find the identity of your father.


>A USELESS INSULT FROM A USELESS WHITE TRASH BASTARD!

rightwing

6/9/2009 2:42:00 PM

0

On Tue, 09 Jun 2009 12:23:44 GMT, nospam@here.org
(Vladimir Tschenko) wrote:

>>A USELESS INSULT FROM A USELESS WHITE TRASH BASTARD!
>>
>Hey, it's the affirmative action boy.
>
>Long time, no see.

What happened to your fake accent, you moron?

nospam

6/9/2009 2:44:00 PM

0

On Tue, 09 Jun 2009 08:41:46 -0600, rightwing@ignorant.com wrote:

>On Tue, 09 Jun 2009 12:23:44 GMT, nospam@here.org
>(Vladimir Tschenko) wrote:
>
>>>A USELESS INSULT FROM A USELESS WHITE TRASH BASTARD!
>>>
>>Hey, it's the affirmative action boy.
>>
>>Long time, no see.
>
>What happened to your fake accent, you moron?

Mr Wonderful let his pet white nigger boy off the leash again.