ruby-1.9

Ruby: require vs require_relative - best practice to workaround running in both Ruby <1.9.2 and >=1.9.2

你离开我真会死。 提交于 2019-11-26 06:52:24
问题 What is the best practice if I want to require a relative file in Ruby and I want it to work in both 1.8.x and >=1.9.2? I see a few options: just do $LOAD_PATH << \'.\' and forget everything do $LOAD_PATH << File.dirname(__FILE__) require \'./path/to/file\' check if RUBY_VERSION < 1.9.2, then define require_relative as require , use require_relative everywhere where it\'s needed afterwards check if require_relative already exists, if it does, try to proceed as in previous case use weird

What is the difference between Ruby 1.8 and Ruby 1.9

亡梦爱人 提交于 2019-11-26 06:13:27
问题 I\'m not clear on the differences between the \"current\" version of Ruby (1.8) and the \"new\" version (1.9). Is there an \"easy\" or a \"simple\" explanation of the differences and why it is so different? 回答1: Sam Ruby has a cool slideshow that outline the differences. In the interest of bringing this information inline for easier reference, and in case the link goes dead in the abstract future, here's an overview of Sam's slides. The slideshow is less overwhelming to review, but having it

invalid multibyte char (US-ASCII) with Rails and Ruby 1.9

核能气质少年 提交于 2019-11-26 06:11:12
问题 I\'m using Ruby 1.9.1 with Rails 2.3.4 My application is to handle text input If I try something like (the inside quotation marks look different) text = \"”“\" I get the following error: #<SyntaxError: /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII) /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII) /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: syntax

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

Is there any difference between the `:key => “value”` and `key: “value”` hash notations?

点点圈 提交于 2019-11-25 22:27:53
问题 Is there any difference between :key => \"value\" (hashrocket) and key: \"value\" (Ruby 1.9) notations? If not, then I would like to use key: \"value\" notation. Is there a gem that helps me to convert from :x => to x: notations? 回答1: Yes, there is a difference. These are legal: h = { :$in => array } h = { :'a.b' => 'c' } h[:s] = 42 but these are not: h = { $in: array } h = { 'a.b': 'c' } # but this is okay in Ruby2.2+ h[s:] = 42 You can also use anything as a key with => so you can do this: