secret
Last active

user classes example

  • Download Gist
example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
class User
 
attr_accessor :classes
 
def initialize
@classes = []
end
 
def add_class(klass)
@classes << klass
end
 
def do_something_with_classes
@classes.each { |klass| puts klass.to_s }
end
end
 
class Klass
def initialize(name)
@name = name
end
 
def to_s
@name
end
end
 
abed_nadir = User.new
abed_nadir.add_class(Klass.new("History of Ice Cream"))
abed_nadir.do_something_with_classes
# => History of Ice Cream

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.