Created
February 5, 2024 20:46
-
-
Save peterbe/d039c5f1d3ced3b62ad3c51530d64e94 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
class TestClass | |
def self.some_other_method | |
puts "Hi" | |
end | |
def my_instance_method | |
puts "My instance method" | |
end | |
# Also possible and convenient when you | |
# have to define many class methods. | |
class << self | |
def first_method | |
puts "FIRST" | |
end | |
def second_method_etc | |
puts "SECOND" | |
end | |
end | |
end | |
i = TestClass.new | |
puts i.my_instance_method # Works | |
TestClass.some_other_method # Works | |
TestClass.first_method # Works | |
TestClass.new.first_method # Fails | |
i.first_method # Fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment