Skip to content

Instantly share code, notes, and snippets.

@luckydev
Created April 14, 2011 03:37
Show Gist options
  • Save luckydev/918849 to your computer and use it in GitHub Desktop.
Save luckydev/918849 to your computer and use it in GitHub Desktop.
Objects gets more power over time.
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
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
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