my_lambda = ->(x) { print x }
my_proc = proc { |x| print x }
def my_method(x)
print x
end
class MyClass
def self.my_static_method(x)
print x
end
end
nums = Array(1..3)
# using a block
nums.each { |x| print x }
# using a lambda/proc
nums.each(&my_lambda)
nums.each(&my_proc)
#using a method
nums.each(&method(:my_method))
# using a static method
nums.each(&MyClass.method(:my_static_method)) # (1)
nums.each { |x| MyClass.my_static_method(x) } # same as (1)
To embed this project on your website, copy the following code and paste it into your website's HTML: