A Zillion Ruby Kōans

NOTE: Because of formatting, I couldn’t have a curly bracket with a colon and an “o” or it turns up with some unavailable WordPress Emoticon URI. So thus I have changed items with this naming to :z_one and :z_two respectively.

Yup, still moving through all the Ruby Koans. There are, after all 276 of these things! 😉 So no more yapping, onto the notes and green lighting the tests. Cheers!

def test_creating_hashes
  empty_hash = Hash.new
  assert_equal Hash, empty_hash.class
  assert_equal({ }, empty_hash)
  assert_equal 0, empty_hash.size
end

def test_hash_literals
  hash = { :z_one  => "uno", :z_two => "dos" }
  assert_equal 2, hash.size
end

def test_accessing_hashes
  hash = { :z_one => "uno", :z_two => "dos" }
  assert_equal "uno", hash[:z_one]
  assert_equal "dos", hash[:z_two]
  assert_equal nil, hash[:doesnt_exist]
end

From test_creating_hashes a Hash.new or {} both appear to create a new empty hash object. The second test creates and adds values to the hash. The third test has asserts that verify the data is inserted in the positions that are expected.

def test_changing_hashes
  hash = { :z_one => "uno", :z_two => "dos" }
  hash[:z_one] = "eins"

  expected = { :z_one => "eins", :z_two => "dos" }
  assert_equal true, expected == hash

  # Bonus Question: Why was "expected" broken out into a variable
  # rather than used as a literal?
end

Again, the hash is setup into the hash variable. Then the expected is setup in another variable. Since Ruby is pointer oriented, the expected variable is setup identical to the hash variable to assure that they truly are identical.

def test_hash_is_unordered
  hash1 = { :z_one => "uno", :z_two => "dos" }
  hash2 = { :z_two => "dos", :z_one => "uno" }

  assert_equal true, hash1 == hash2
end

def test_hash_keys
  hash = { :z_one => "uno", :z_two => "dos" }
  assert_equal 2, hash.keys.size
  assert_equal true, hash.keys.include?(:z_one)
  assert_equal true, hash.keys.include?(:z_two)
  assert_equal Array, hash.keys.class
end

def test_hash_values
  hash = { :z_one => "uno", :z_two => "dos" }
  assert_equal 2, hash.values.size
  assert_equal true, hash.values.include?("uno")
  assert_equal true, hash.values.include?("dos")
  assert_equal Array, hash.values.class
end

test_hash_is_unordered shows that a hash, no matter the order the values are assigned, assigns them to the values that are directly set to.

def test_combining_hashes
  hash = { "jim" => 53, "amy" => 20, "dan" => 23 }
  new_hash = hash.merge({ "jim" => 54, "jenny" => 26 })

  assert_equal true, hash != new_hash

  expected = { "jim" => __, "amy" => 20, "dan" => 23, "jenny" => __ }
  assert_equal false, expected == new_hash
end

This test asserts that the two different hashes are different, nothing amazing or odd there. The second part asserts that the next and expected hashes are different. Which again, is what we expect.

def test_default_value
  hash1 = Hash.new
  hash1[:z_one] = 1

  assert_equal 1, hash1[:z_one]
  assert_equal nil, hash1[:z_two]

  hash2 = Hash.new("dos")
  hash2[:z_one] = 1

  assert_equal 1, hash2[:z_one]
  assert_equal "dos", hash2[:z_two]
end

This test confirms that a hash with a request against a hash position that isn’t assigned to yet returns nil. The later two asserts show that a number compared to the hash position that contains a number compares as a number, and a string compared to a position that has a string also compares as equal.

Until next time, hack some koans.

OS Bridge Week in Review

This is the first time I’ve attended OS Bridge. I’d known about it before while living in PDX. I had seen numerous people sitting in Bailey’s, Backspace, and other places around town after the days of the conference in past years. This year I actually got to experience it myself and am stoked with the experience!

The conference started off proper on Tuesday and is wrapping up today (Friday). It has been a great ride. The conference is a community organized event, but you’d think it was a high end professional conference in many ways. The food was awesome, the sessions covered a huge range of topics, and people at the conference had a great attitude and energy around learning about the open source community and what it’s about!

High Points

There are a couple of things that really stood out to me above other aspects of the conference.

People

People in the OSS Community are not like other communities that I have often interacted with in the past. The OSS Community as a whole is a lot less likely to focus on negatives and instead is much more focused on learning, knowing new technologies, and creation of new software ideas, experiences, and opportunities. This by far sets the OSS Community apart from many other software communities. Open source software, with its very positive attitude about the future is in turn becoming the future of software development (Arguable, it already is).

Projects

The projects are some of the most wide ranging of many conferences that I’ve attended. Ranging from algorithms of odd complexities to zoological studies. There is no unturned stone in the realm of open source software. One of the binding themes in most of the projects, which is really what brings out an awesome aspect of open source, is that the projects are very community driven. I don’t mean just software community, but communities in general. The transit app, which of course would be one of my favorites (re: Transit Sleuth), is centered around enabling businesses within a community to encourage transit usage (something I strongly believe is fundamental to strong communities in urban areas). One other project was a geolocation game (see last blog entry) that encouraged socializing IRL (In Real Life) instead of just via the Internet on a device. This is the type of software that truly changes the way we live, the way we interact, and the way we as people better ourselves.

Panoramic Portland, Oregon (Click for larger image)

Panoramic Portland, Oregon (Click for larger image)

Portland

The final thing I wanted to mention, was how awesome Portland is for a conference like this. Many cities are NOT good for technical conferences, at least if you intend to geek out, study, learn, and actually make progress.  Las Vegas is often used and it is a horrible city. Los Angeles, can be good sometimes but often the conferences are held in the middle of nowhere. The list of places that are bad for conferences can get long, and conference organizers should take note. But Portland has a uniqueness that is unlike anywhere else in the United States. The list of positives is massive. The city is walkable, leave your car far away from the city, life is better here without it. The food options are huge, with the best food cart scene in the United States, arguably the world (see the tail end of my day #2 Coverage). Anthony Bordain has literally said the best food cities in America are New Orleans, Portland, Seattle, and New York which I can absolutely agree with (having lived in all but one of those cities now, but visited all of them many times). The list continues; coffee, beer, food, walk ability, massive bookstore (Powell’s), etc., etc.

Summary

I’m just gonna hit up a bullet list for this purpose, because the summary items are simple:

  • Portland is one of the best cities for technical conferences, hands down.
  • The people and the projects these people are working on at OS Bridge are amazing, life changing projects!

With that, I’m wrapping up my OS Bridge Coverage. I’m looking forward to next year already and seeing familiar and new faces. May the code flow forth on your open source efforts. Cheers!

Total Event Coverage by me, Adron:  Day #1, Day #2, and Day #3 Big news and Day #3 Review.

Coverage by John DeRosa:  Day #1, Day #2, Day #3, and Day #4.

Coverage by @Demew: Open Source Bridge 2011

Coverage by @brainwane OS Bridge 2011

Coverage by Open Source Labs (OSL) OSL OS Bridge Coverage