Skip to content
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

Add Object#peek as helper method to inspect object #7243

Closed
wants to merge 1 commit into from

Conversation

sikachu
Copy link
Member

@sikachu sikachu commented Aug 3, 2012

This method is very helpful when inspecting and debug the code. So, instead of you having to do this:

@user.tap{ |u| puts u.inspect }.activate!

Now you can do:

@user.peek.activate!

So, instead of you having to do this:

  @user.tap{ |u| puts u.inspect }.activate!

Now you can do:

  @user.peek.activate!
@jherdman
Copy link
Contributor

jherdman commented Aug 3, 2012

Maybe I'm just really naive, but why do we need this? I can honestly say I've never used this pattern before. I'd love to hear more about its use case.

@spastorino
Copy link
Contributor

👎 from me

@jeremy
Copy link
Member

jeremy commented Aug 3, 2012

I do this sometimes, but rarely with puts. Doesn't merit a method on Object IMO.

@sikachu
Copy link
Member Author

sikachu commented Aug 3, 2012

I think it's just a gimmick for saving you some time. So, instead of having to fix the whole line, or type .tap { |o| puts o.inspect }, I can just call .peek, run the test, and i'll see the "#inspect" result.

So, these are more use cases:

User.active.where(:created_at => 10.days.ago)

If I want to print out active users for debugging purpose, instead of having to:

User.active.tap{ |u| puts u.inspect }.where(:created_at => 10.days.ago)

I'd just

User.active.peek.where(:created_at => 10.days.ago)

Also, adding #peek at the end of the line when it'll get assigned to the variable is easy:

@users = User.active.where(:created_at => 10.days.ago).peek
# instead of
@users = User.active.where(:created_at => 10.days.ago)
puts @users.inspect

@tenderlove
Copy link
Member

I haven't looked at the diff yet, but the name "peek" seems bad. It's a common name in parsers, queues, etc and has a very different meaning.

Aaron Patterson
http://tenderlovemaking.com/
I'm on an iPhone so I apologize for top posting.

On Aug 2, 2012, at 8:16 PM, Prem Sichanugristreply@reply.github.com wrote:

This method is very helpful when inspecting and debug the code. So, instead of you having to do this:

@user.tap{ |u| puts u.inspect }.activate!

Now you can do:

@user.peek.activate!

You can merge this Pull Request by running:

git pull https://github.com/sikachu/rails master-peek

Or you can view, comment on it, or merge it online at:

#7243

-- Commit Summary --

  • Add Object#peek as helper method to inspect object

-- File Changes --

M activesupport/CHANGELOG.md (2)
M activesupport/lib/active_support/core_ext/object.rb (1)
A activesupport/lib/active_support/core_ext/object/peek.rb (7)
A activesupport/test/core_ext/object/peek_test.rb (38)
M guides/source/active_support_core_extensions.textile (9)

-- Patch Links --

https://github.com/rails/rails/pull/7243.patch
https://github.com/rails/rails/pull/7243.diff


Reply to this email directly or view it on GitHub:
#7243

@sikachu
Copy link
Member Author

sikachu commented Aug 3, 2012

Thanks for the review guys. I was thinking this would be helpful, but seems like no one uses it (and has a bad method name.) I couldn't think of the better name though.

Anyway, closing this for now. If anybody has a different opinion feel free to reopen/merge it. Thanks. :D

@sikachu sikachu closed this Aug 3, 2012
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.

5 participants