Thursday, October 11, 2012

Works with Ruby super keyword

1.9.3-head :001 > class Person
1.9.3-head :002?>   end
 => nil
1.9.3-head :003 > class Employee < Person
1.9.3-head :004?>   def hello
1.9.3-head :005?>     super
1.9.3-head :006?>     end
1.9.3-head :007?>   end
 => nil
1.9.3-head :008 > e = Employee.new
 => #<Employee:0x007fc011062f60>
1.9.3-head :009 > e.hello
NoMethodError: super: no superclass method `hello' for #<Employee:0x007fc011062f60>
    from (irb):5:in `hello'
    from (irb):9
    from /Users/laileo/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
1.9.3-head :010 > class Person
1.9.3-head :011?>   def hello
1.9.3-head :012?>     'person hello'
1.9.3-head :013?>     end
1.9.3-head :014?>   end
 => nil
1.9.3-head :015 > e.hello
 => "person hello"

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.