Sha256: 262d8042ac40bbcc3249b70ebba24d16f1767f7feb51575c8ca1684523b7a147

Contents?: true

Size: 940 Bytes

Versions: 8

Compression:

Stored size: 940 Bytes

Contents

# encoding: utf-8

# this is only here so we can test I18n works nicely with ActiveSupports
# with_options. Maybe we can just remove it?

class Object
  def with_options(options)
    yield ActiveSupport::OptionMerger.new(self, options)
  end
end

module ActiveSupport
  class OptionMerger #:nodoc:
    instance_methods.each do |method|
      undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
    end

    def initialize(context, options)
      @context, @options = context, options
    end

    private
      def method_missing(method, *arguments, &block)
        if arguments.last.is_a?(Proc)
          proc = arguments.pop
          arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
        else
          arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
        end

        @context.__send__(method, *arguments, &block)
      end
  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
pepe-i18n-0.2.0 test/with_options.rb
thedarkone-i18n-0.2.0 test/with_options.rb
polish-0.0.5 lib/vendor/i18n/test/with_options.rb
polish-0.0.4 lib/vendor/i18n/test/with_options.rb
polish-0.0.3 lib/vendor/i18n/test/with_options.rb
polish-0.0.2 lib/vendor/i18n/test/with_options.rb
i18n-0.3.0 test/with_options.rb
polish-0.0.1 lib/vendor/i18n/test/with_options.rb