One minute
Different ways to call a method in Ruby 💎
wanted to know different ways to call a method in ruby? 🤔
Check this out -
class MyClass
def method_name
puts "Public method inside MyClass"
end
end
❯ MyClass.new.method_name
❯ MyClass.new::method_name
❯ MyClass::new::method_name
❯ MyClass.new.send(:method_name) # work with private methods
❯ MyClass.new.method(:method_name).call
❯ MyClass.new.method(:method_name).()
Reference
Read other posts
comments powered by Disqus