Permalink
Browse files

Get rid of --old-style-hash

  • Loading branch information...
1 parent 500ca98 commit 9cf38be008aff555b3aecc53a6f18800cea30a71 @josevalim josevalim committed Dec 20, 2011
@@ -60,9 +60,6 @@ def self.add_shared_options_for(name)
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
:desc => "Show this help message and quit"
-
- class_option :old_style_hash, :type => :boolean, :default => false,
- :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9"
end
def initialize(*args)
@@ -255,14 +252,9 @@ def git_keep(destination)
create_file("#{destination}/.gitkeep") unless options[:skip_git]
end
- # Returns Ruby 1.9 style key-value pair if current code is running on
- # Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise.
+ # Returns Ruby 1.9 style key-value pair.
def key_value(key, value)
- if options[:old_style_hash] || RUBY_VERSION < '1.9'
- ":#{key} => #{value}"
- else
- "#{key}: #{value}"
- end
+ "#{key}: #{value}"
end
end
end
@@ -9,9 +9,6 @@ class NamedBase < Base
class_option :skip_namespace, :type => :boolean, :default => false,
:desc => "Skip namespace (affects only isolated applications)"
- class_option :old_style_hash, :type => :boolean, :default => false,
- :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9"
-
def initialize(args, *options) #:nodoc:
@inside_template = nil
# Unfreeze name in case it's given as a frozen string
@@ -337,18 +337,7 @@ def test_no_active_record_or_test_unit_if_skips_given
def test_new_hash_style
run_generator [destination_root]
assert_file "config/initializers/session_store.rb" do |file|
- if RUBY_VERSION < "1.9"
- assert_match(/config.session_store :cookie_store, :key => '_.+_session'/, file)
- else
- assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file)
- end
- end
- end
-
- def test_force_old_style_hash
- run_generator [destination_root, "--old-style-hash"]
- assert_file "config/initializers/session_store.rb" do |file|
- assert_match(/config.session_store :cookie_store, :key => '_.+_session'/, file)
+ assert_match(/config.session_store :cookie_store, key: '_.+_session'/, file)
end
end
@@ -77,33 +77,14 @@ def test_actions_are_turned_into_methods
assert_file "app/mailers/notifier.rb" do |mailer|
assert_instance_method :foo, mailer do |foo|
- if RUBY_VERSION < "1.9"
- assert_match(/mail :to => "to@example.org"/, foo)
- else
- assert_match(/mail to: "to@example.org"/, foo)
- end
+ assert_match(/mail to: "to@example.org"/, foo)
assert_match(/@greeting = "Hi"/, foo)
end
assert_instance_method :bar, mailer do |bar|
- if RUBY_VERSION < "1.9"
- assert_match(/mail :to => "to@example.org"/, bar)
- else
- assert_match(/mail to: "to@example.org"/, bar)
- end
+ assert_match(/mail to: "to@example.org"/, bar)
assert_match(/@greeting = "Hi"/, bar)
end
end
end
-
- def test_force_old_style_hash
- run_generator ["notifier", "foo", "--old-style-hash"]
- assert_file "app/mailers/notifier.rb" do |mailer|
- assert_match(/default :from => "from@example.com"/, mailer)
-
- assert_instance_method :foo, mailer do |foo|
- assert_match(/mail :to => "to@example.org"/, foo)
- end
- end
- end
end
@@ -126,18 +126,7 @@ def self.all(klass)
def test_new_hash_style
run_generator
assert_file "app/controllers/users_controller.rb" do |content|
- if RUBY_VERSION < "1.9"
- assert_match(/\{ render :action => "new" \}/, content)
- else
- assert_match(/\{ render action: "new" \}/, content)
- end
- end
- end
-
- def test_force_old_style_hash
- run_generator ["User", "--old-style-hash"]
- assert_file "app/controllers/users_controller.rb" do |content|
- assert_match(/\{ render :action => "new" \}/, content)
+ assert_match(/\{ render action: "new" \}/, content)
end
end
end

13 comments on commit 9cf38be

@KieranP

Noooooo! I actually prefer the old style hash syntax because the new one doesn't support objects as keys. :-(

{ author: person, person: [posts] }

won't work for example.

{ author: person, person => [posts] }

is a horrible mix of both syntaxes.

Ruby 1.9 never should have added the new format.

@sobrinho
Contributor

I agree, 1.8 style supports any object as key and 1.9 style not.

Sure we can change when needed but rails projects will be a mix of hash style :(

Maybe is not responsibility of rails handle this but is a good start!

@egilburg
Contributor

1.9 style also doesn't support keywords as keys
{:for => "Me"} # Fine
{for: "Me"} # Syntax error

@dissolved
Contributor

WHY?!? It is still valid syntax. Why would you remove this feature?

@rafaelfranca
Member

Because we prefer the new syntax in our codebase and in the generated files.

@dissolved
Contributor

But by doing so, you force it upon everyone's codebase (via generated files).

@mdespuits
Contributor

Rails is decidedly in favor of the Ruby 1.9 syntax. For the most part, Rubyists and Rails-ists tend to use plain symbols for keys in hashes, not objects. I don't see any places recommending other objects as keys, only a few people deciding to use it that way.

Rails is opinionated.

@dissolved
Contributor

All is not lost though, I just discovered the hash_syntax gem which seems to work.

https://github.com/michaeledgar/hash_syntax

@mdespuits
Contributor

Yes! That is my favorite tool for the job on an older project.

@dissolved
Contributor

I understand Rails is opinionated... I've worked in this space since 2006. But a central piece of the "Rails is Omakase" philosophy, is you are able to substitute out that damn unagi. Rails had that in 3.x. It was opinionated (and why shouldn't it be) and defaulted to 1.9 hash syntax. That's cool, since Rails was Omakase, I could substitute it for my own opinion that 1.8 hash syntax is easier to read. But instead of allowing that substitution, Rails is becoming more like the Soup Nazi--"No 1.8 syntax for you! Come back, one year!"

As long as the above mentioned hash_syntax gem allows me to fix my code, then I'll not fight this (losing) battle. But don't sound the "Rails is opinionated" rally cry!

@sikachu
Member
sikachu commented on 9cf38be Mar 7, 2013
  1. This commit is in master. It's targeting Rails 4.0, which requires at least Ruby 1.9.3, so I don't think compatibility is an issue (and I don't think you'll be able to run Rails 4 on Ruby 1.8.7 anyway.)
  2. This is only applied to generated code from Rails, which aren't really in that many places. You're still welcomed to write your code using old style hash syntax.
  3. 3-2-stable still including support for this option. It will also not generate Ruby 1.9 hash style if you're running the generator on Ruby 1.8.7.
  4. I saw this argument earlier, but running a different Ruby version in your production and development environment is just insane. Stick with one version of Ruby (preferably 1.9.3) everywhere and you'll save yourself from headache.
@mdespuits
Contributor

@dissolved Why can't I say "Rails is opinionated"? It's true. Besides, I'm not the opinion behind Rails, and I wouldn't want to be. Probably wouldn't like my opinions either 😉. Just a reminder that once Rails has an opinion, it's a losing battle, but not necessarily one for the worse... (e.g. asset pipeline)

Your point about Omakase is something I had not thought about, but maybe that's because I prefer the 1.9 syntax anyway.

@dissolved
Contributor

@sikachu I think you are completely missing the point, as I am running on Ruby 2.0 (both in development and production), do indeed use 1.8 style in my own code. The old style hash was NOT deprecated in Ruby 1.9 or 2.0 (to my knowledge). This is a Rails opinion (and agreed, they are welcome to it).

@mattdbridges You can say anything you want, of course ;-) I guess I should have simply said that I grow tired of the "Rails is opinionated" response. It is the equivalent of an adult saying to a child, "because I said so."

Anyway, I'll waive off this. I wouldn't have mentioned it at all had I been aware of the hash_syntax gem.

Please sign in to comment.