Skip to content

Instantly share code, notes, and snippets.

@crisward
Created December 10, 2016 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisward/2f74e30059ee8905571f327afa24fa7c to your computer and use it in GitHub Desktop.
Save crisward/2f74e30059ee8905571f327afa24fa7c to your computer and use it in GitHub Desktop.
crystal passing class method as a callback
class Do
def that
x = 10
while x > 0
yield x
x-=1
end
end
end
class Doer
def dothing(that)
that do | num |
puts num
end
end
end
# I want to wrap do.that in doer
@sdogruyol
Copy link

class Do
  def that(&block)
    x = 10
    while x > 0
      yield x
      x -= 1
    end
  end
end

class Doer
  def dothing(&that)
    Do.new.that do |num|
      puts num
    end
  end
end

Doer.new.dothing do |num|
  pp num
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment