Created
April 14, 2011 03:37
-
-
Save luckydev/918849 to your computer and use it in GitHub Desktop.
Objects gets more power over time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def say_hi | |
puts "Hi, this is Ruby!" | |
end | |
end | |
john = Person.new | |
robin = Person.new | |
john.say_hi # => Hi, this is Ruby! | |
robin.say_hi # => Hi, this is Ruby! | |
module MyMethods | |
def shout_hello | |
puts "Hellloooo People" | |
end | |
end | |
john.extend(MyMethods) | |
john.shout_hello # => Hellloooo People | |
robin.shout_hello # => NoMethodError: Undefined Method shout_hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def say_hi | |
puts "Hi, this is Ruby!" | |
end | |
end | |
john = Person.new | |
robin = Person.new | |
john.say_hi # => Hi, this is Ruby! | |
robin.say_hi # => Hi, this is Ruby! | |
def john.shout_hello | |
puts "Hellloooo People" | |
end | |
john.shout_hello # => Hellloooo People | |
robin.shout_hello # => NoMethodError: Undefined Method shout_hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def say_hi | |
puts "Hi, this is Ruby!" | |
end | |
end | |
john = Person.new | |
robin = Person.new | |
john.say_hi # => Hi, this is Ruby! | |
robin.say_hi # => Hi, this is Ruby! | |
class Person | |
def shout_hello | |
puts "Hellloooo People" | |
end | |
end | |
john.shout_hello # => Hellloooo People | |
robin.shout_hello # => Hellloooo People | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment