Skip to content

Instantly share code, notes, and snippets.

@arekt
Created Sep 6, 2012
Embed
What would you like to do?
to_proc
class Filter
def initialize()
@constraints = []
end
def constraint(&block)
@constraints << block
end
def to_proc
lambda { |e| @constraints.all? {|fn| fn.call(e) }}
end
end
if __FILE__ == $0
filter = Filter.new
filter.constraint {|x| x > 10 }
filter.constraint {|x| x.even? }
p (8..34).select(&filter)
p (8..34).select(&filter.to_proc)
puts ['a','b','c'].map(&:upcase)
class Symbol
def to_proc
lambda { |e| puts "You want me to do #{self}. hahaha no way" }
end
end
puts ['a','b','c'].map(&:upcase)
end
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment