Hash assignment (1.9.2)

Apparently ruby 1.9 allows a shortcut hash creation/assignment syntax

h = {foo: “bar”}
=> {:foo=>“bar”}

I ran across this today after converting an application to rails 3.1
over the last few month with release candidates and trying test
deploying it. The application was developed using ruby 1.9.2 and is a
combination of copy and paste from old, create new scaffolds and then
adjust, etc. Really no real problems with the conversion, until I
tried to run it on an old PPC macmini that is limited to 1.8.7 (my
server!). I’ve been meaning to update this but have not had a reason
until now.

Now the problem is not my code, since I didn’t know about this new
syntax until today. It is with the generated code. For instance /
config/initializers/session_store.rb created with 1.9.2 contains:

Ngg::Application.config.session_store :cookie_store, key:
‘_ngg_session’

A new application created with 3.1 and using 1.8.7 contains:

Ngg::Application.config.session_store :cookie_store, :key =>
‘_ngg_session’

That line would generate one of the first of many errors you’d get if
you’d try to run the 1.9.2 application on a 1.8.7 machine.

I guess the bottom line is that if you are going to deploy with ruby
1.8.7, you better use 1.8.7 to develop the application and not have
contributors using 1.9.2. Don’t know if Rails has any caveats on this,
but should.

I would of searched for treads on this, but not sure what I would have
searched for.

Steve

Steve

On Sep 8, 12:44pm, AppleII717 [email protected] wrote:

Apparently ruby 1.9 allows a shortcut hash creation/assignment syntax

h = {foo: “bar”}
=> {:foo=>“bar”}

Yup, that was added to 1.9

That line would generate one of the first of many errors you’d get if
you’d try to run the 1.9.2 application on a 1.8.7 machine.

I guess the bottom line is that if you are going to deploy with ruby
1.8.7, you better use 1.8.7 to develop the application and not have
contributors using 1.9.2. Don’t know if Rails has any caveats on this,
but should.

Rails itself should work on both 1.8.7 and 1.9.2. I would certainly
recommend that you develop using something that matches what you’ll be
deploying with as closely as possible.

Fred