Skip to content

Instantly share code, notes, and snippets.

@revans
Created February 23, 2015 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revans/de3474e1f81bc7dfaad5 to your computer and use it in GitHub Desktop.
Save revans/de3474e1f81bc7dfaad5 to your computer and use it in GitHub Desktop.
# 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