Reputation: 173
i believe Ruby supports this by default. i need to create bunch of class variables, but don't want to override already defined variables and i don't know which of them will have been defined. I expect something similar to class_attribute but it should create variable which starts with underscore.
Upvotes: 0
Views: 129
Reputation: 1013
ActiveSupport has attr_internal
. Here is question on it: what is attr_internal used for
For class attribute just use class << self
.
For plain ruby you can use class_attribute
to define accessors with _
in the begin, and then add aliases.
Upvotes: 1
Reputation: 1652
Yes. You can begin a variable with an underscore. For example:
_hello = "_hello"
hello = "hello"
puts _hello
#=> "_hello"
puts hello
#=> "hello"
Upvotes: 0