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 6635619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:04:38+00:00 2026-05-25T23:04:38+00:00

Given a method: def x(*a) Can calling it like so: x(‘foo’, y: ‘bar’, z:

  • 0

Given a method:

def x(*a)

Can calling it like so:

 x('foo', y: 'bar', z: 'baz')

Ever differ from:

@yz = { y: 'bar', z: 'baz' }
x('foo', @yz)

I’m asking because I’ve found the I18n.translate method, defined as:

def translate(*args)
  options  = args.last.is_a?(Hash) ? args.pop : {}
  key      = args.shift
  backend  = config.backend
  locale   = options.delete(:locale) || config.locale
  handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise

  raise I18n::ArgumentError if key.is_a?(String) && key.empty?

  result = catch(:exception) do
    if key.is_a?(Array)
      key.map { |k| backend.translate(locale, k, options) }
    else
      backend.translate(locale, key, options)
    end
  end
  result.is_a?(MissingTranslation) ? handle_exception(handling, result, locale, key, options) : result
end

…behaves differently when called using the different approaches above. When passing in a variable instead of the inline hash, then locale is always set to config.locale and the built-in locale fallbacks mechanism is prevented from running (regardless of whether :locale is present in the hash variable.) Yet, in IRB tests, I can’t find a way for #x to tell the difference.

I’ve worked around this for the moment by copy-pasting the hash contents into each #translate call in the app affected, but sure would by nice to know what’s up here.

  • 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-05-25T23:04:39+00:00Added an answer on May 25, 2026 at 11:04 pm

    no, they are identical:

    def x(*a)
      puts a.inspect
    end
    
    x('foo', y: 'bar', z: 'baz')
     => ["foo", {:y=>"bar", :z=>"baz"}]
    
    @yz = { y: 'bar', z: 'baz' }
    
    x('foo', @yz)
     => ["foo", {:y=>"bar", :z=>"baz"}]
    

    Please note that the syntax you’re using will only work in Ruby 1.9 , not in 1.8

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following module, module Foo def bar :baz end end def send_to_foo(method) #
given module Foo def bar puts foobar end end I can do String.extend(Foo) and
Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html
Given that a function a_method has been defined like def a_method(arg1, arg2): pass Starting
I wrote a function like def cmd_run(host=localhost, port=8000): Run server at given host port
Given the following method: def some_method :value end The following statements work as I
Given: case class Foo(a: Int, b: String, c: Double) you can say: val params
What is the easiest way to test (using reflection), whether given method (i.e. java.lang.Method
Given a method signature: public bool AreTheSame<T>(Expression<Func<T, object>> exp1, Expression<Func<T, object>> exp2) What would
Given a method DoSomething that takes a (parameterless) function and handles it in some

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.