Skip to content

Instantly share code, notes, and snippets.

@granolocks
Created September 24, 2013 21:01
Show Gist options
  • Select an option

  • Save granolocks/6691178 to your computer and use it in GitHub Desktop.

Select an option

Save granolocks/6691178 to your computer and use it in GitHub Desktop.
class methods for kevin
class MySexyClass
def self.this_is_a_class_method
"class method called"
end
def this_is_an_instance_method
"instance method called"
end
end
#
# These are called against the base class:
#
MySexyClass.this_is_a_class_method
# => "class method called"
MySexyClass.this_is_an_instance_method
# NoMethodError: undefined method `this_is_an_instance_method' for MySexyClass:Class
#
# These are called against an instance of the base class:
#
MySexyClass.new.this_is_a_class_method
# NoMethodError: undefined method `this_is_a_class_method' for #<MySexyClass:0x0000000231d6c8>
MySexyClass.new.this_is_an_instance_method
# => instance method called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment