Skip to content

Instantly share code, notes, and snippets.

@insoul
Created October 10, 2013 12:57

Revisions

  1. insoul created this gist Oct 10, 2013.
    37 changes: 37 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    class A
    def yield_block
    yield
    end

    def call_block(&block)
    block.call
    end

    def eval_block(&block)
    instance_eval(&block)
    end
    end

    class B
    def initialize
    @a = A.new
    end

    def yield_test
    @a.yield_block { puts self.class }
    end

    def call_test
    @a.call_block { puts self.class }
    end

    def eval_test
    @a.eval_block { puts self.class }
    end
    end

    b = B.new
    b.yield_test #=> B
    b.call_test #=> B
    b.eval_test #=> A