T
T
TeiSinTai2017-10-19 11:32:57
ruby
TeiSinTai, 2017-10-19 11:32:57

Can the following code work?

There is a class method with a declaration

def create(time: nil, user: nil, event: nil, status: nil, user_ip: nil)

It is called like this:
body = YAML.load(yaml_body)
success, status = SomeLib::SomePart::SomeClass.create(body)

body looks like this (result of body.inspect):
{"eventMillis"=>"12340981201",  "userLogin"=>"someUser", "typeCode"=>"USR_AUTH", "resultCode"=>"SUCCESS", "ipAddress"=>"127.0.0.1"}

Actually, the specified code produces an error "wrong number of arguments (1 for 0)."
Ruby version 2.1.5p273
My knowledge of ruby ​​is limited to what I have read in my free time in the last couple of days, so I would like to know if the above code can work - on some other version of ruby, with some additional library/configuration .... In general, is there any chance that it does not work for reasons other than "wrongly written".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh_shi, 2017-10-19
@TeiSinTai

Can not. Or the keys in the hash should be named the same as the parameters:
Or you have to manually describe each parameter:

success, status = SomeLib::SomePart::SomeClass.create(time: body['eventMillis'], user: body['userLogin'], event: body['typeCode'], status: body['resultCode'], user_ip: body['ipAddress'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question