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
14
votes
2 answers

What are the benefits of the new hash syntax in Ruby 1.9?

Apart from making it sightly more concise for defining hashes with symbols as keys, are there any other benefits of writing a hash as: {key1: "value1", key2: "value2"} instead of {:key1 => "value1", :key2 => "value2"}? Also, what is the convention…
zsquare
  • 9,916
  • 6
  • 53
  • 87
13
votes
8 answers

Detect encoding

I'm getting some string data from the web, and I suspect that it's not always what it says it is. I don't know where the problem is, and I just don't care any more. From day one on this project I've been fighting Ruby string encoding. I really want…
Phil Kulak
  • 6,960
  • 8
  • 45
  • 50
13
votes
4 answers

Ruby 1.9, YAML, and string encodings: how to lead a life of sanity?

It seems to me that the YAML library that ships with ruby 1.9 is encoding-deaf. What this means is that when generating YAML, it'll take any string of bytes, and escape any byte sequence that doesn't output clean ASCII. That's lame, but…
kch
  • 77,385
  • 46
  • 136
  • 148
13
votes
5 answers

Understanding Ruby symbol as method call

class A def test "Test from instance" end class << self def test "Test from class" end end end p A.send(:test) # "Test from class" p A.new.method(:test).call # "Test from instance" Here symbol works…
sunny1304
  • 1,684
  • 3
  • 17
  • 30
13
votes
3 answers

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu. Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools…
Arta
  • 5,127
  • 5
  • 25
  • 23
12
votes
2 answers

How to mix a module into an rspec context

How can I mix a module into an rspec context (aka describe), such that the module's constants are available to the spec? module Foo FOO = 1 end describe 'constants in rspec' do include Foo p const_get(:FOO) # => 1 p FOO …
Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
12
votes
7 answers

How can I use US-style dates in Rails using Ruby 1.9?

I'm in the U.S., and we usually format dates as "month/day/year". I'm trying to make sure that my Rails app, using Ruby 1.9, assumes this format everywhere, and works the way it did under Ruby 1.8. I know that lots of people have this issue, so I'd…
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
12
votes
3 answers

Set global default encoding for ruby 1.9

I want to tell ruby that everything is utf8, except when stated otherwise, so I dont have to place these # encoding: utf-8 comments everywhere.
grosser
  • 14,707
  • 7
  • 57
  • 61
12
votes
4 answers

What does "Anonymous modules have no name to be referenced by" really mean?

I'm upgrading my Rails app to work with Ruby 1.9 and I keep encountering errors like this: Anonymous modules have no name to be referenced by /home/foo/.gem/ruby/1.9.1/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:585:in…
ScottJ
  • 1,080
  • 12
  • 20
12
votes
1 answer

Splat on a hash

A splat on a hash converts it into an array. [*{foo: :bar}] # => [[:foo, :bar]] Is there some hidden mechanism (such as implicit class cast) going on here, or is it a built-in primitive feature? Besides an array, are nil and hash the only things…
sawa
  • 165,429
  • 45
  • 277
  • 381
11
votes
2 answers

What are Ruby's numbered global variables

What do the values $1, $2, $', $` mean in Ruby?
Morrowless
  • 6,856
  • 11
  • 51
  • 81
11
votes
6 answers

Accessing compiled routes in Grape / Rack::Mount::Route

I'm trying to generate a list of all routes generated by my subclass of Grape::API (MyApi). I can get close by calling: MyApi.send(:route_set).instance_variable_get(:@routes) which gives me an array of Rack::Mount::Route objects. The only attribute…
Josh
  • 621
  • 6
  • 10
11
votes
3 answers

In Ruby CSV, how to write a blank ,, instead of ,"", to a file?

Ruby 1.9 version of csv header %w[first second third] data = ["column one",,"column three"] CSV.open("myfile.csv","w") do |csv| csv << header csv << data end In this simple example, the empty middle ,, in the data array causes an error but if…
sf2k
  • 592
  • 2
  • 6
  • 25
11
votes
4 answers

How do Enumerators work in Ruby 1.9.1?

This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else …
horseyguy
  • 29,455
  • 20
  • 103
  • 145
11
votes
2 answers

String#encode not fixing "invalid byte sequence in UTF-8" error

I know there are multiple similar questions about this error, and I've tried many of them without luck. The problem I'm having involves the byte \xA1 and is throwing ArgumentError: invalid byte sequence in UTF-8 I've tried the following with no…
joshm1
  • 553
  • 1
  • 10
  • 21