diff 1-Ruby/hashes-irb.output @ 15:ebb19742b98f

Add some minor experiments with hashes (hash tables)
author IBBoard <dev@ibboard.co.uk>
date Tue, 03 Jan 2017 20:36:16 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1-Ruby/hashes-irb.output	Tue Jan 03 20:36:16 2017 +0000
@@ -0,0 +1,21 @@
+hashes.rb(main):001:0> #! /usr/bin/env ruby
+hashes.rb(main):002:0* 
+hashes.rb(main):003:0* # Ruby has inline hashmap definitions, like PHP.
+hashes.rb(main):004:0* # Java doesn't. C# isn't quite as clear as this "key => value" pattern.
+hashes.rb(main):005:0* frenchify = { 'one' => 'un', 'two' => 'deux' }
+=> {"one"=>"un", "two"=>"deux"}
+hashes.rb(main):006:0> puts frenchify['one']
+un
+=> nil
+hashes.rb(main):007:0> 
+hashes.rb(main):008:0* # Or, done properly with symbols:
+hashes.rb(main):009:0* frenchify = { :one => 'un', :two => 'deux' }
+=> {:one=>"un", :two=>"deux"}
+hashes.rb(main):010:0> puts frenchify[:one]
+un
+=> nil
+hashes.rb(main):011:0> # But what is a symbol? Its own class, apparently!
+hashes.rb(main):012:0* puts :one.classhashes.rb(main):012:0* 
+hashes.rb(main):012:0> 
+Symbol
+=> nil