Sha256: 1eb07e274e9529bd2e377c0df485390df01dfe7b0981997105c01c705b4f8750

Contents?: true

Size: 648 Bytes

Versions: 9

Compression:

Stored size: 648 Bytes

Contents

require "spec_helper"

describe Object, ".method_object" do
  it "creates a .call class method that instantiates and runs the #call instance method" do
    klass = Class.new do
      method_object :foo

      def call
        foo
      end
    end

    assert klass.call(true)
    refute klass.call(false)
  end

  it "doesn't require attributes" do
    klass = Class.new do
      method_object

      def call
        true
      end
    end

    assert klass.call
  end

  it "passes along any block" do
    klass = Class.new do
      method_object

      def call
        yield
      end
    end

    assert klass.call { :foo } == :foo
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
attr_extras-7.0.0 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.5 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.4 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.3 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.2 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.1 spec/attr_extras/method_object_spec.rb
attr_extras-6.2.0 spec/attr_extras/method_object_spec.rb
attr_extras-6.1.0 spec/attr_extras/method_object_spec.rb
attr_extras-5.2.0 spec/attr_extras/method_object_spec.rb