Skip to content

Instantly share code, notes, and snippets.

@latentflip
Forked from morganp/ruby_map.rb
Created September 21, 2010 15:55
Show Gist options
  • Save latentflip/589915 to your computer and use it in GitHub Desktop.
Save latentflip/589915 to your computer and use it in GitHub Desktop.
#Subclassing Array instead of including Enumerable
class Core < Array
attr_reader :name
def initialize( name, data )
@name = name
self[0..-1] = data
end
end
require 'pp'
a = Core.new( 'dave', [1,2,3,4] )
puts a.name
pp a
puts
a.each do |x|
puts x.to_s
end
puts
pp a
a.map! do |element|
element = element * 2
end
pp a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment