Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Created April 14, 2017 01:18
Show Gist options
  • Select an option

  • Save benkoshy/2aec1228c9ff4b97b4b56f977f2ae745 to your computer and use it in GitHub Desktop.

Select an option

Save benkoshy/2aec1228c9ff4b97b4b56f977f2ae745 to your computer and use it in GitHub Desktop.
Showing how many changes required if now using a hash
# consider the situation where the boss
# required you to use a hash.
# notice how many changes are made:
# just two. This means the code is
# much easier to maintain and easier
# to subsequently change. Because you will
# only be making those changes in a few places
# vs changing everything everywhere!


class Person
	attr_reader :age, :weight
  
  # change made inside the class.
	def initialize(data)
		@age = data[:age]
    @weight = data[:weight]
	end
end

# 1 change here.
p = Person.new({age: 35, weight: 150})


age = p.age
weight = p.weight
p1 = Person.new([50, 110])
p1_age = p1.age
p1_weight = p1.weight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment