Skip to content

Instantly share code, notes, and snippets.

@osazemeu
Last active May 19, 2025 12:45
Show Gist options
  • Save osazemeu/2903f70d564cfd3ff62f844f08b2da3d to your computer and use it in GitHub Desktop.
Save osazemeu/2903f70d564cfd3ff62f844f08b2da3d to your computer and use it in GitHub Desktop.
[1,2,3].map{|x| x.to_s}
[1,2,3].map(&:to_s)
Proc.new{|x| x.to_s}
def sym_to_proc(sym)
Proc.new{ |x| x.send(sym) }
end
sym_to_proc(:to_s).call(3)
:to_s.to_proc.call(3)
[1,2,3].map &->(n) { n.to_s }
require 'Date'
%w(2014-05-04 2014-04-03 2014-02-01).map{|x| Date.parse(x)}
Object.method(:==)
Object.method(:==).to_proc
%(2014-05-04 2014-02-01 2014-04-03).tap(&Date.method(:parse))
names = %w{fred jess john}
ages = [38, 47, 91]
locations = %w{spain france usa}
p names.zip(ages)
p Hash[names.zip]
p names.zip[ages, locations]
names.zip(ages, locations) do |foo|
p foo
end
class X
def self.make_stuff(*meths)
meths.each do |meth|
define_method(meth) do
__method__
end
end
end
end
make_stuff :a, :b, :c
x = X.new
p x.a
p x.b
p x.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment