Skip to content

Instantly share code, notes, and snippets.

View pjb3's full-sized avatar

Paul Barry pjb3

View GitHub Profile
@pjb3
pjb3 / symbol_expressions.rb
Created May 25, 2011 11:32 — forked from bmuller/symbol_expressions.rb
Symbol Expressions Simplified
class Symbol
def |(*args)
@args = args
self
end
def to_proc
Proc.new { |obj|
obj.send *[self] + (@args || [])
}
# best way to code: if event is nil, true, otherwise if event.user == user true, else false
# seems clear but is so vertically long for such a simple thing
if event
event.user == user
else
true
end
# nice and compact but wtf does it mean
# I hear that aliasing lambda is bad, but this is
# much more readable...
def this_block(&block)
block
end
this_block{ @this.destroy }.should change(Thing, :count).by(-1)