Conversation
api.rb
Outdated
There was a problem hiding this comment.
This is perfectly valid --- just want to show one way to get values out of a hash. I'm not sure I'd even use it here, but when you need to extract values out of an arguments hash inside a method, this is pretty cool:
time, message, execution_time = params.values_at("time", "msg", "exec_time")
LogRequest.log_request time, message, execution_timeHere's a simple example: http://rubyfiddle.com/riddles/e78d5
|
Looks really great. No style or logic notes to give |
|
Eagle complete. |
api.rb
Outdated
There was a problem hiding this comment.
In this case, I'd probably use the params["user"] syntax. (so many choices)... but I think this might be more readable
if params["user"]
@logs = LogRequest.log_per_user(params.fetch("user"))
else
@logs = LogRequest.log
endThe reason this works, is that if you have a hash, and ask it for a key it does not have, it'll return nil. and nil is falsy, so you can do
if nil
# never executed
else
puts "hi"
end|
Nicely done with the User... I liked how you did User.None -- the idea being that's how you can get a nill user, and used the select on user.id as the equality. Simple and works well. If you're interested in the concept of a NilClass -- that is, a class that represents a nil instance instead of a real object, check out https://github.com/avdi/naught. Advanced stuff, but kinda cool. |
|
Thank you. I really learned a lot this time. |
I intend to do the Eagle part too.