Module: Enumerable
- Defined in:
- lib/tengine/support/core_ext/enumerable/deep_freeze.rb,
lib/tengine/support/core_ext/enumerable/map_to_hash.rb,
lib/tengine/support/core_ext/enumerable/each_next_tick.rb
Instance Method Summary collapse
- #deep_freeze ⇒ Object
-
#each_next_tick ⇒ Object
“You are not expected to understand this.
-
#map_to_hash(key_method = nil, &block) ⇒ Object
このメソッド名はダサイので良い名前募集してます。.
Instance Method Details
#deep_freeze ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 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 ⇒ Object
“You are not expected to understand this. … The real problem is
that we didn't understand what was going on either.''
Dennis Ritcie
8 9 10 11 12 13 14 15 16 17 18 19 |
# 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) ⇒ Object
このメソッド名はダサイので良い名前募集してます。
10 11 12 13 14 15 16 17 18 |
# File 'lib/tengine/support/core_ext/enumerable/map_to_hash.rb', line 10 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 |