On Jun 2, 9:31 pm, James Byrne <[email protected]>
wrote:
> I want do do something like this
>
> class MyClass
>
> def default
> self.default
> end
this creates an infinite recursion - self.default doesn't call the
class method, it's equivalent to writing
def default
default
end
which obviously doesn't work.
You could write
def default
MyClass.default
end
or, equivalently
def default
self.class.default
end
the code as is won't quite work, since ruby will complain if you try
to access an unset class variable, so you need some thing like
class MyClass
@@default = 'this
...
end
@@ variables are visible by instances as well as classes though, so
you could also do
def default
@@default
end
Lastly, active support already includes the cattr_accessor helper that
will create accessors for you
Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---