Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created February 5, 2024 20:46
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 peterbe/d039c5f1d3ced3b62ad3c51530d64e94 to your computer and use it in GitHub Desktop.
Save peterbe/d039c5f1d3ced3b62ad3c51530d64e94 to your computer and use it in GitHub Desktop.
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