# consider this person class:
class Person
attr_reader :age, :weight
def initialize(data)
@age = data[0]
@weight = data[1]
end
end
p = Person.new([35, 150])
# now let's access this person's age.
# notice now we don't care whether
# the underlying data structure is a hash,
# or is an array. All we know (and care) is that
# if we send an "age" message to the p Person
# then we will get that Person's age.
age = p.age
# same goes for her weight
weight = p.weight
p1 = Person.new([50, 110])
p1_age = p1.age
p1_weight = p1.weight
Last active
April 14, 2017 01:15
-
-
Save benkoshy/a465373e754503e3bddbd56ffe70d467 to your computer and use it in GitHub Desktop.
Example where data structure is hidden
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment