I have seen this in initializers in rails (config/initializers/foo.rb)
module foo
module bar
def self.biz
@blahblah = "what am i"
end
end
end
How is self used?
What instance is @blahblah being attached to?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
self in ruby is a method on the class itself, not an object.
So if you have
Then you can call
SuperHero.awesome?In your example, you have added a class method to Foo::Bar
So you can call .biz on the class (which is a module Bar in the Foo module)