Skip to content

Instantly share code, notes, and snippets.

@skoji
Created December 30, 2011 10:55
Show Gist options
  • Save skoji/1539290 to your computer and use it in GitHub Desktop.
Save skoji/1539290 to your computer and use it in GitHub Desktop.
why this code won't run on ruby 1.8.7? (it runs on 1.9.3)
require 'pp'
class Bar
attr_accessor :foo_bars
def initialize(&block)
@foo_bars = []
yield self
end
def foo_bar(&block)
@foo_bars.push(block)
end
def run(x)
@foo_bars.each do
|foo_bar|
pp foo_bar.call(x)
end
end
end
pp Bar.new {
|b|
b.foo_bar do
|x|
if x.nil?
'x is empty!'
else
"x is #{x}"
end
end
b.foo_bar do
|x|
x.gsub(/^(.)/,'f\1')
end
}.run("0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment