简体   繁体   中英

Call method to generate arguments in ruby works in 1.8.7 but not 1.9.3

This is something that I had working in ruby 1.8.7, but no longer works in 1.9.3, and I am not sure what changes make this fail.

Previously, I had something like this

myFunction(submitArgs())

where submitArgs was a helper method that could be called with some options

def submitArgs(args={})
  #Some logic/manipulations
  ["Text", args]
end

Then myFunction would be called with the first argument "Text", and the second a hash. Now in 1.9.3, it is being called with "Text {}" all as one big string.

Does anyone know what change was made between the ruby versions that causes this, and if there is an alternative to returning an array of arguments in 1.9.3?

Change required (in github notation):

- myFunction(submitArgs())
+ myFunction(*submitArgs)

The reason that [I assume] myFunction is declared taking two arguments:

def myFunction a1, a2

Hence the array must be splatted before passing to it. I wonder how that worked in 1.8 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM