Sha256: 7dc98040df3add031f5054f93520ee0b64c84ca5070ba0b260c4247438d9c067

Contents?: true

Size: 462 Bytes

Versions: 3

Compression:

Stored size: 462 Bytes

Contents

module Helloable
  refine(Object) do
    def hello
      puts :hello
    end
  end
end

module Hiable
  refine(Object) do
    def hi
      puts :hi
    end
  end
end


class Person
  using WithRefinements

  def initialize(with:)
    @things = Array(with)
  end

  def greet(&block)
    with_refinements(*@things, &block)
  end
end

a = Person.new(with: Hiable)
b = Person.new(with: Helloable)

a.greet do
  hello rescue hi
end

b.greet do
  hi rescue hello
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
with_refinements-0.3.0 examples/greeting.rb
with_refinements-0.2.0 examples/greeting.rb
with_refinements-0.1.0 examples/greeting.rb