-
Notifications
You must be signed in to change notification settings - Fork 8
Pand and Tiger complete #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
api.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.