Sha256: 020029ea6c3d2912a9e4b29a480c8e375cf2e79b4f80213837687e4ba70a27b9

Contents?: true

Size: 740 Bytes

Versions: 27

Compression:

Stored size: 740 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

27 entries across 27 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.149 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.148 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.147 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.146 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.145 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.144 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.143 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.142 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.141 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.140 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.139 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.138 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.137 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.136 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.135 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.134 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.133 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.132 lib/open_classes/array/gte_gte.rb
tbpgr_utils-0.0.131 lib/open_classes/array/gte_gte.rb