Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Last active January 13, 2016 16:08
Show Gist options
  • Save osyo-manga/3c1acf72cf619cf7b147 to your computer and use it in GitHub Desktop.
Save osyo-manga/3c1acf72cf619cf7b147 to your computer and use it in GitHub Desktop.
momonga
class Object
def _
self_ = self
Class.new(BasicObject) do
define_singleton_method(:method_missing) do |name, *args, &block|
return self_.__send__(name, *args, &block) unless block && block.parameters.size == 0
self_.__send__(name, *args) do |*args|
Object.new.instance_eval do
define_singleton_method(:_) { args[0] }
args.size.times do |i|
define_singleton_method("_#{i + 1}") { args[i] }
end
instance_eval &block
end
end
end
end
end
end
name = "homu"
0._.upto(3){
p _1 + _1
}
p [1, 2, 3]._.map { _ * 10 }
p [5, 3, 2, 6, 1, 4]._.sort { _2 <=> _1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment