Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8184101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:23:07+00:00 2026-06-07T01:23:07+00:00

I was trying to do an open source contribution, and the line of code

  • 0

I was trying to do an open source contribution, and the line of code in the star_rating method below with options.merge() (this is the change I tried to submit) was kicked back with the following message “This is invalid Ruby syntax (in both 1.8.7 and 1.9.3)…” My question is why? I checked the Hash#merge method on the ruby interactive shell and it seems to work.

def star_rating(options = {})
   ##original line of code
   has_many :rates_without_dimension, :as => :rateable, :class_name => 'RateMe', :dependent => :destroy, :conditions => {:dimension => nil}  

  ##line of code I tried to submit
  has_many :rates_without_dimension, :as => :rateable, options.merge(:class_name => 'RateMe'), :dependent => :destroy, :conditions => {:dimension => nil}  
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:23:09+00:00Added an answer on June 7, 2026 at 1:23 am

    This is indeed invalid syntax. The last arguments of a method call can be a Hash, in which case Ruby allows you to drop the enclosing {}:

    foo(1, 2, 3, :a => 4, :b => 5)
    # equivalent to:
    foo(1, 2, 3, {:a => 4, :b => 5})
    

    In your case, you have :as => :rateable before a simple argument (options.merge), that’s not allowed.

    If you inverted them, you still wouldn’t get the effect you want:

    has_many :rates_without_dimension, options.merge(:class_name => 'RateMe'), :as => :rateable, :dependent => :destroy, :conditions => {:dimension => nil}
    # same as
    has_many :rates_without_dimension, options.merge(:class_name => 'RateMe'), {:as => :rateable, :dependent => :destroy, :conditions => {:dimension => nil}}
    # => has 3 arguments, not 2.
    

    What you can do here is insure you are passing two parameters. One way to do this:

    has_many :rates_without_dimension, options.merge(:class_name => 'RateMe', :as => :rateable, :dependent => :destroy, :conditions => {:dimension => nil})
    

    Note that in Ruby 2.0, it will be possible to do what you wanted using the equivalent of the splat operators for arrays (*) which will be ** for hashes:

    h = {:b => 2}
    foo(:a => 1, **h, :c => 3)
    # same as
    foo(:a => 1, :b => 2, :c => 3) 
    
    # so you will be allowed to write:
    has_many :rates_without_dimension, :as => :rateable, **options.merge(:class_name => 'RateMe'), :dependent => :destroy, :conditions => {:dimension => nil}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to modify some open source code to change how it filters
I'm trying to compile open source tool abc. When I tried to build the
When trying to discover something in the code of some open source C projects,
This is a part of an open source project called JNotify. I am trying
Trying to understand this open source app on github, it has a gem file:
recently I downloaded this open source project and I am trying to compile it.
I'm trying to download the source code for a large open source project, so
I'm trying to understand some code I found the open source oauth-php library. The
Our development uses lots of open-source code and I'm trying to figure out what
i'm trying to program a drawer function into Smultron (an open source code editor)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.