Created
September 24, 2013 21:01
-
-
Save granolocks/6691178 to your computer and use it in GitHub Desktop.
class methods for kevin
This file contains hidden or 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 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