hashrocket

What does the “=>” in “rescue Exception => e” do?

本小妞迷上赌 提交于 2021-01-27 16:45:03
问题 Given the example: def method_of_doom my_string = "I sense impending doom." my_string.ah_ha_i_called_a_nonexistent_method rescue NoMethodError => e: puts "PROBLEM: " + e.to_s rescue Exception: puts "Uhh...there's a problem with that there method." end On the line where it says: rescue NoMethodError => e: What is the '=>' doing? How is it different than this usage: module FighterValues BAMBOO_HEAD = { 'life' => 120, 'hit' => 9 } DEATH = { 'life' => 90, 'hit' => 13 } KOALA = { 'life' => 100,

What does the “=>” in “rescue Exception => e” do?

左心房为你撑大大i 提交于 2021-01-27 16:42:15
问题 Given the example: def method_of_doom my_string = "I sense impending doom." my_string.ah_ha_i_called_a_nonexistent_method rescue NoMethodError => e: puts "PROBLEM: " + e.to_s rescue Exception: puts "Uhh...there's a problem with that there method." end On the line where it says: rescue NoMethodError => e: What is the '=>' doing? How is it different than this usage: module FighterValues BAMBOO_HEAD = { 'life' => 120, 'hit' => 9 } DEATH = { 'life' => 90, 'hit' => 13 } KOALA = { 'life' => 100,

In Ruby what does “=>” mean and how does it work? [duplicate]

拥有回忆 提交于 2019-12-17 22:39:06
问题 This question already has an answer here : What is the “equals greater than” operator => in Ruby? (1 answer) Closed 5 years ago . While learning Ruby I've come across the "=>" operator on occasion. Usually I see it in the form of :symbol => value and it seems to be used frequently when passing values to functions. What exactly is that operator called? What does it do/mean? Is it built into Ruby or is it something that different frameworks like Rails and DataMapper add to the symbol class? Is

What's the difference between colon “:” and fat arrow “=>” [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:27:03
问题 This question already has answers here : Is there any difference between the `:key => “value”` and `key: “value”` hash notations? (5 answers) Closed 6 years ago . What's the difference between colon : and fat arrow => in Ruby? Or when to use what? :foo => true foo: true 回答1: The syntax is for defining Hash key/value pairs, and the difference depends on the Ruby version. Supported in both Ruby 1.8 and Ruby 1.9 :foo => true Supported only in Ruby 1.9 foo: true If you're developing in Ruby 1.9

Ruby/Rails hash rockets Syntax [closed]

江枫思渺然 提交于 2019-12-02 16:26:18
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Can someone point me to a good primer just explaining the different syntactic features in Ruby/Rails? For instance, how come some examples I see do myMethod(x: "z") and others do myMethod(:x => "x") ? The syntax in general seems strange to me, just looking for a quick at-a-glance reference to use as a cheat

Ruby/Rails hash rockets Syntax [closed]

こ雲淡風輕ζ 提交于 2019-12-02 09:36:36
Can someone point me to a good primer just explaining the different syntactic features in Ruby/Rails? For instance, how come some examples I see do myMethod(x: "z") and others do myMethod(:x => "x") ? The syntax in general seems strange to me, just looking for a quick at-a-glance reference to use as a cheat sheet. MrYoshiji They are the same , it is just a matter of preferences. I also asked myself why would we add this new syntax if we already have one? Well, Programming with Ruby implies that we are lazy and want to type the less possible caracters. So this new syntax allow us - lazy

In Ruby what does “=>” mean and how does it work? [duplicate]

淺唱寂寞╮ 提交于 2019-11-28 19:07:18
This question already has an answer here: What is the “equals greater than” operator => in Ruby? 1 answer While learning Ruby I've come across the "=>" operator on occasion. Usually I see it in the form of :symbol => value and it seems to be used frequently when passing values to functions. What exactly is that operator called? What does it do/mean? Is it built into Ruby or is it something that different frameworks like Rails and DataMapper add to the symbol class? Is it only used in conjunction with the symbol class? Thanks. => separates the keys from the values in a hashmap literal. It is

What's the difference between colon “:” and fat arrow “=>” [duplicate]

风格不统一 提交于 2019-11-28 09:39:16
This question already has an answer here: Is there any difference between the `:key => “value”` and `key: “value”` hash notations? 5 answers What's the difference between colon : and fat arrow => in Ruby? Or when to use what? :foo => true foo: true JDutil The syntax is for defining Hash key/value pairs, and the difference depends on the Ruby version. Supported in both Ruby 1.8 and Ruby 1.9 :foo => true Supported only in Ruby 1.9 foo: true If you're developing in Ruby 1.9 you should probably use the syntax: foo: true as it appears to be the direction the community is moving in. Alex Peattie The

Is Hash Rocket deprecated?

半腔热情 提交于 2019-11-26 15:07:43
The well-cited RIP Hash rocket post would seem to imply the Hash Rocket syntax ( :foo => "bar" ) is deprecated in favor of the new-to-Ruby JSON-style hash ( foo: "bar" ), but I can't find any definitive reference stating the Hash Rocket form is actually deprecated/unadvised as of Ruby 1.9. The author of that blog post is being overly dramatic and foolish, the => is still quite necessary . In particular: You must use the rocket for symbols that require quoting: :'where.is' => x is valid but 'where.is': x is not. Ruby 2.2 has fixed this problem so you can say 'where.is': x in Ruby 2.2+. You must

Is Hash Rocket deprecated?

余生长醉 提交于 2019-11-26 04:17:25
问题 The well-cited RIP Hash rocket post would seem to imply the Hash Rocket syntax ( :foo => \"bar\" ) is deprecated in favor of the new-to-Ruby JSON-style hash ( foo: \"bar\" ), but I can\'t find any definitive reference stating the Hash Rocket form is actually deprecated/unadvised as of Ruby 1.9. 回答1: The author of that blog post is being overly dramatic and foolish, the => is still quite necessary. In particular: You must use the rocket for symbols that require quoting: :'where.is' => x is