Created
February 23, 2015 20:53
-
-
Save revans/de3474e1f81bc7dfaad5 to your computer and use it in GitHub Desktop.
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
# Instance Methods | |
class Demo | |
def say_hi | |
puts "hi" | |
end | |
end | |
Demo.new.say_hi # => 'hi' | |
# the say_hi is an instance method of the Demo class | |
# Class Methods | |
# | |
class Demo | |
def self.say_hi | |
puts "hi" | |
end | |
end | |
Demo.say_hi # => 'hi' | |
# the say_hi is a class method for the Demo class | |
# Instance Eval | |
Demo.instance_eval do | |
def say_goodbye | |
puts 'goodbye' | |
end | |
end | |
Demo.say_goodbye # => 'goodbye' | |
# the say_goodbye is a class method for the Demo class | |
# Class Eval | |
Demo.class_eval do | |
def say_goodbye | |
puts 'goodbye' | |
end | |
end | |
Demo.new.say_goodbye # => 'goodbye' | |
# the say_goodbye is an instance method for the Demo class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment