module Enumerable

Public Instance Methods

deep_freeze() click to toggle source
# File lib/tengine/support/core_ext/enumerable/deep_freeze.rb, line 2
def deep_freeze
  each do |i|
    case i
    when String # 1.8.7 tweak
      i.freeze
    when Enumerable
      i.deep_freeze
    else
      i.freeze
    end
  end
  freeze
end
each_next_tick() { |obj| ... } click to toggle source

“You are not expected to understand this. … The real problem is

that we didn't understand what was going on either.''
                                                   Dennis Ritcie
# File lib/tengine/support/core_ext/enumerable/each_next_tick.rb, line 8
def each_next_tick
  raise ArgumentError, "no block given" unless block_given?
  nop = lambda do end
  self.reverse_each.inject nop do |block, obj|
    lambda do
      EM.next_tick do
        yield obj
        block.call
      end
    end
  end.call
end
map_to_hash(key_method = nil, &block) click to toggle source

このメソッド名はダサイので良い名前募集してます。

# File lib/tengine/support/core_ext/enumerable/map_to_hash.rb, line 9
def map_to_hash(key_method = nil, &block)
  block ||= lambda{|i| i}
  inject({}) do |d, i|
    key = key_method ? i.send(key_method) : i
    raise Tengine::Support::UniqueKeyError, "duplicated key found: #{key.inspect}" unless d[key].nil?
    d[key] = block.call(i)
    d
  end
end