Sha256: 8e32742294f5e8f96888526ce6f70661de71ff3610d1b2d92f25e92da7c75cbb

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

It is used in ContextR as well, and its
redefinition is simple, The functionality of method missing is 
one of the core ingredients of cleanly designed Ruby programs, it is still 
possible to extend it with context-dependent behaviour.

The following code will show the right usage.

    class MethodMissingExample
      def method_missing(*a)
        "base"
      end

      in_layer :one do
        def method_missing(*a, &b)
          "pre_one " + super
        end
      end
      in_layer :two do
        def method_missing(*a, &b)
          super + " post_two"
        end
      end
    end

    example do
      instance = MethodMissingExample.new
      result_of(instance.any_method) == "base"

      ContextR::with_layer :one do
        result_of(instance.any_method) == "pre_one base"
      end
      ContextR::with_layer :two do
        result_of(instance.any_method) == "base post_two"
      end

      ContextR::with_layer :one, :two do
        result_of(instance.any_method) == "pre_one base post_two"
      end
    end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contextr-1.0.3 test/method_missing.mkd
contextr-1.0.0 test/method_missing.mkd
contextr-1.0.1 test/method_missing.mkd
contextr-1.0.2 test/method_missing.mkd