Self during Ruby class initialization
When you are defining the initialize method of a Ruby class, should you be calling class or instance methods from that class?
You should be calling instance methods. Once the interpreter begins executing the initialize method, your instance has already been instantiated. Thus, self refers to the instance.
class Foo
def initialize
puts self.class
end
end
Foo.new
#=> Foo
Written by Robbie Pitts
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#