Skip to content

Conversation

@meltar
Copy link

@meltar meltar commented May 29, 2013

I intend to do the Eagle part too.

api.rb Outdated
Copy link
Member

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_time

Here's a simple example: http://rubyfiddle.com/riddles/e78d5

@jwo
Copy link
Member

jwo commented May 30, 2013

Looks really great. No style or logic notes to give

@meltar
Copy link
Author

meltar commented Jun 4, 2013

Eagle complete.

api.rb Outdated
Copy link
Member

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
end

The 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

@jwo
Copy link
Member

jwo commented Jun 4, 2013

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.

@meltar
Copy link
Author

meltar commented Jun 8, 2013

Thank you. I really learned a lot this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants