Sha256: 7be724b5508f53f9965b3a440a87bec07f52026ce2a4c665e25a60824796ab9a

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

# encoding: utf-8

class ArrayContext
  attr_reader :receiver

  def initialize(receiver)
    @receiver = receiver
  end

  def method_missing(method_name, *args, &block)
    if args.size > 0
      receiver.map do |value|
        value.send method_name, *args
      end
    else
      receiver.map do |value|
        value.send method_name
      end
    end
  end

  def to_a
    @receiver
  end
end

# Array
class Array
  # return ArrayContext for each execute
  #
  # === Example
  #
  #   [*'a'..'c'].>>.ord # => [97, 98, 99]
  #   [*'a'..'c'].>>.'ord' # => [97, 98, 99]
  #   [*'aa'..'ac'].>>.gsub("a", "c") # => ['cc', 'cb', 'cc']
  #
  def >>(dummy = nil)
    ArrayContext.new(self)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/array/gte_gte.rb