Skip to content

Instantly share code, notes, and snippets.

@JustinAiken
Last active December 16, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinAiken/dc00605c07c70e89abad to your computer and use it in GitHub Desktop.
Save JustinAiken/dc00605c07c70e89abad to your computer and use it in GitHub Desktop.
user classes example
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment