Skip to content

Instantly share code, notes, and snippets.

@abrongersma
Created September 16, 2012 06:25
Show Gist options
  • Save abrongersma/3731283 to your computer and use it in GitHub Desktop.
Save abrongersma/3731283 to your computer and use it in GitHub Desktop.
def smiley(hash)
myhash = {"happy" => ":)"}
hash.each do |key, value|
end
myhash["happy"]
end
@envaman
Copy link

envaman commented Sep 16, 2012

def smiley(key)
if {:mood =>"happy"}
":)"
elsif {:mood => "sad"}
":("
elsif {:mood => "weird"}
":|"
end
end

@envaman
Copy link

envaman commented Sep 16, 2012

def smiley(key)
if {:mood => "happy"}
":)"
elsif {:mood => "sad"}
":("
elsif {:mood => "weird"}
":|"
end
end

def smiley(key)
if {:mood => "happy"}
":)"
end
if {:mood => "sad"}
":("
end
if {:mood => "weird"}
":|"
end
end

@envaman
Copy link

envaman commented Sep 16, 2012

/app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/configuration.rb:730:in load': /tmp/d20120916-28-ltvvg6/hashes/spec/happy-or-sad_spec.rb:2: syntax error, unexpected tASSOC, expecting keyword_then or ';' or '\n' (SyntaxError) if mood => happy ^ from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/configuration.rb:730:inblock in load_spec_files'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/configuration.rb:730:in map' from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/configuration.rb:730:inload_spec_files'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/command_line.rb:22:in run' from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/runner.rb:69:inrun'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/rspec-core-72c7ac5a76cc/lib/rspec/core/runner.rb:10:in `block in autorun'

@abrongersma
Copy link
Author

def smiley(hash)
myhash = {"happy" => ":)"}
myhash[hash[:mood]]
end

@abrongersma
Copy link
Author

def smiley(hash)
myhash = {"happy" => ":)", "sad" => ":(", "weird" => ":|"}
myhash[hash[:mood]]
end

@abrongersma
Copy link
Author

hash = {"mood" => "happy"}
hash["mood"]
== "happy"

@abrongersma
Copy link
Author

Hash[ [ ["a", 100], ["b", 200] ] ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment