Questions tagged [ruby-1.9]

Ruby 1.9 is a shortcut for ruby versions 1.9.1, 1.9.2 and 1.9.3. Ruby is a dynamic language that focuses on simplicity and expressiveness.

Ruby is a dynamic language that focuses on simplicity and expressiveness.

Ruby 1.9 is the successor of Ruby version 1.8, there are the subversions 1.9.1, 1.9.2 and 1.9.3. The successor Ruby 2.0 was published 2013-02-24.

Ruby 1.9 is incompatible with Ruby 1.8, the succcessor Ruby 2.0 is intended to be fully backward compatible with Ruby 1.9.3.

Ruby 1.9 introduced new features like:

  • Per-string character encodings are supported
  • Block local variables (variables that are local to the block in which they are declared)
  • An additional lambda syntax
  • New socket API (IPv6 support)
  • require_relative import security
429 questions
200
votes
6 answers

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

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: #
Tam
  • 11,872
  • 19
  • 69
  • 119
154
votes
11 answers

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

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…
GreyCat
  • 16,622
  • 18
  • 74
  • 112
141
votes
5 answers

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

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?
AdamNYC
  • 19,887
  • 29
  • 98
  • 154
106
votes
1 answer

Is Hash Rocket deprecated?

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…
mahemoff
  • 44,526
  • 36
  • 160
  • 222
102
votes
4 answers

What is the difference between Ruby 1.8 and Ruby 1.9

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?
salt.racer
  • 21,903
  • 14
  • 44
  • 51
89
votes
15 answers

Invalid gemspec because of the date format in specification

When I include a gem that I made, thanks to Bundler (version 1.0.12), in a Gemfile and then I try to bundle or to rake just like that: $ rake I've got this error message: Invalid gemspec in…
Zag zag..
  • 6,041
  • 6
  • 27
  • 36
57
votes
4 answers

Ruby 1.9 hash with a dash in a key

In ruby 1.9 is there a way to define this hash with the new syntax? irb> { a: 2 } => {:a=>2} irb> { a-b: 2 } SyntaxError: (irb):5: syntax error, unexpected tLABEL { a-b: 2 } ^ with the old one, it's working: irb> { :"a-b" => 2 } =>…
makevoid
  • 3,276
  • 2
  • 33
  • 29
57
votes
5 answers

How do I make Ruby 1.9 the default Ruby on Ubuntu?

Is there any way, on Ubuntu 9.04, to install Ruby 1.8 as ruby1.8 (or get rid of it altogether) and have Ruby 1.9 be the default ruby?
Martin DeMello
  • 11,876
  • 7
  • 49
  • 64
47
votes
1 answer

What's the difference between Object and BasicObject in Ruby?

What's the difference between these classes? What's the difference between their purposes?
Sergey
  • 47,222
  • 25
  • 87
  • 129
36
votes
4 answers

How do I reference a function in Ruby?

In python, it's fairly straightforward to reference a function: >>> def foo(): ... print "foo called" ... return 1 ... >>> x = foo >>> foo() foo called 1 >>> x() foo called 1 >>> x >>> foo
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
35
votes
1 answer

Ruby - UTF-8 file encoding

We all know the "magical" # encoding: utf-8 line. But I've seen several other alternative notations, some of them pretty wild. Do you know or use any of those? Is there some more general rule of what is acceptable? Edit: Ok, apparently there are…
PJK
  • 2,082
  • 3
  • 17
  • 28
34
votes
3 answers

How to specify output file encoding in Ruby?

How can I set the encoding of a file when using a File#open?
Fluffy
  • 27,504
  • 41
  • 151
  • 234
33
votes
7 answers

How can I avoid putting the magic encoding comment on top of every UTF-8 file in Ruby 1.9?

I have a Rails project with a lot of Cyrillic strings in it. It worked fine on Ruby 1.8, but Ruby 1.9 assumes source files are US-ASCII-encoded unless you provide an # encoding: utf-8 comment at the top of the source file. At that point the files…
Leonid Shevtsov
  • 14,024
  • 9
  • 51
  • 82
32
votes
2 answers

What's the difference between Process.fork and Process.spawn in Ruby 1.9.2

What's the difference between Process.fork and the new Process.spawn methods in Ruby 1.9.2 and which one is better to run another program in a subprocess? As far as I understand Process.fork accepts block of code and Process.spawn takes a system…
Vincent
  • 16,086
  • 18
  • 67
  • 73
32
votes
5 answers

Rails 3 invalid multibyte char (US-ASCII)

I found a similar post here but I can't solve the problem anyway. I got this /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII) /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char…
framomo86
  • 1,205
  • 2
  • 14
  • 17
1
2 3
28 29