Sha256: 073c7c94948accdc4ef710e2b39bfb70e21c91a1992079d2d877cefe2b0a0301
Contents?: true
Size: 909 Bytes
Versions: 2
Compression:
Stored size: 909 Bytes
Contents
module Ru class Iterator class << self def redefined_methods @redefined_methods ||= begin preserved_methods = %{initialize method_missing respond_to? to_a} [].public_methods.select do |method| method = method.to_s method =~ /^[a-z]/ && !preserved_methods.include?(method) end end end end def initialize(array) @array = array end def to_a Ru::Array.new(@array) end def to_stdout to_a.join("\n") end private def method_missing(method, *args, &block) map_method(method, *args, &block) end def map_method(method, *args, &block) @array.map! { |item| item.send(method, *args, &block) } self end redefined_methods.each do |method| define_method(method) do |*args| map_method(method, *args) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ru-0.1.4 | lib/ru/iterator.rb |
ru-0.1.3 | lib/ru/iterator.rb |