Sha256: 0ab270814d2bfe353ea9b5bacc578f57548a70954e81b93046d3fa0859f5b71b
Contents?: true
Size: 773 Bytes
Versions: 119
Compression:
Stored size: 773 Bytes
Contents
module SugarCube class AnonymousArray < Array def [] index o = super.to_object self[index] = o end def first self.size == 0 ? nil : self[0] end def last c = self.size c == 0 ? nil : self[c - 1] end def to_object self end # replace enumerable methods # # In AnonymousArray: # It was not satisfied with the :each method only. [:each, :map, :collect].each do |method| base_method = "anonymousarray_#{method.to_s}".to_sym alias_method base_method, method define_method method do send(base_method) {|o| yield o.to_object} end end end end class NSArray def to_object SugarCube::AnonymousArray.new(self) end end
Version data entries
119 entries across 119 versions & 1 rubygems