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

Let Element#to_s behave the same as Element#inspect #35

Merged
merged 4 commits into from Nov 1, 2014

Conversation

roy
Copy link
Contributor

@roy roy commented Jan 23, 2014

This was discovered by doing

puts element
p element

which gave different results

#<Element:undefined>
#<Element [<input id="some_id" class="some_class">]> 

@elia
Copy link
Member

elia commented Jan 23, 2014

@roy thanks! can you change the #to_s in an alias (or alias_method)?

@adambeynon
Copy link
Contributor

I have recently been using #to_s as an alias to get the text/html of an element, to mirror nokogiri having Node#to_s and NodeSet#to_s to return the inner html representation. This (for me) seems a better fit than using is as an alias of #inspect.

@roy
Copy link
Contributor Author

roy commented Jan 24, 2014

The question is then what we want to output when doing a to_s, in my opinion there are 3 options.

  • the same as toString() in javascript: "[object Object]"
  • output a representation of the object in a ruby way as I'm doing right now: '#<Element [
    ]>'
  • output inner_html (or inner_text)

In my opinion we should do the second option, as that's more expected when using to_s.

@elia
Copy link
Member

elia commented Jan 25, 2014

+1 for outer html, inspect is still there if one needs it

@adambeynon
Copy link
Contributor

Thanks for the request, (finally) merging in. 👍

adambeynon added a commit that referenced this pull request Nov 1, 2014
Let Element#to_s behave the same as Element#inspect
@adambeynon adambeynon merged commit 94073d4 into opal:master Nov 1, 2014
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.

None yet

3 participants