# Tagz and entities

**URL:** <https://www.ruby-forum.com/t/tagz-and-entities/164607>\
**Category:** Ruby\
**Created:** [April 3, 2009, 12:49am UTC](https://www.ruby-forum.com/t/tagz-and-entities/164607 "2009-04-03T00:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [April 3, 2009, 12:49am UTC](https://www.ruby-forum.com/t/tagz-and-entities/164607/1 "2009-04-03T00:49:34Z")

</div>

Is this how tagz.\<\< is supposed to work? It seems that \<\< and #concat  
behave differently w.r.t. entity quoting.

require ‘tagz’  
include Tagz.globally

arrow = “↑”  
html = html\_ {

* * *

tagz \<\< arrow

* * *

tagz.concat arrow

* * *

\_\_\_ arrow  
}

puts html

**END**

Output:

&uarr; ↑

↑

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [April 3, 2009, 7:00am UTC](https://www.ruby-forum.com/t/tagz-and-entities/164607/2 "2009-04-03T07:00:48Z")

</div>

On Apr 2, 2009, at 4:48 PM, Joel VanderWerf wrote:

> Is this how tagz.\<\< is supposed to work? It seems that \<\< and  
> #concat behave differently w.r.t. entity quoting.

correct. escape in the normal case (\<\<) but concat works directly  
without quoting.

cheers.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [April 3, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/tagz-and-entities/164607/3 "2009-04-03T19:56:06Z")

</div>

ara.t.howard wrote:

> On Apr 2, 2009, at 4:48 PM, Joel VanderWerf wrote:
> 
> > Is this how tagz.\<\< is supposed to work? It seems that \<\< and #concat  
> > behave differently w.r.t. entity quoting.
> 
> correct. escape in the normal case (\<\<) but concat works directly  
> without quoting.

Thanks. That seems a bit arbitrary since these methods are the same for  
strings. It’s something you just have to remember, but then forget when  
you come back to the code after a while.

Would it be possible for the object returned by #tagz to have a method,  
say #literally or #unescaped, which returns an object which delegates  
back to the original. On the original Tagz::Document, #\<\< and #concat  
have the same quoting behavior. On the delegator, they do not quote.

Just a thought…

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Joel\_VanderWerf](https://www.ruby-forum.com/u/Joel_VanderWerf)\
**Post date:** [April 5, 2009, 5:31pm UTC](https://www.ruby-forum.com/t/tagz-and-entities/164607/4 "2009-04-05T17:31:46Z")

</div>

On Apr 3, 2009, at 11:54 AM, Joel VanderWerf wrote:

> Thanks. That seems a bit arbitrary since these methods are the same  
> for strings. It’s something you just have to remember, but then  
> forget when you come back to the code after a while.

yeah i can see that. i was thinking more of erb’s concat - which  
appends literal objects.

> Would it be possible for the object returned by #tagz to have a  
> method, say #literally or #unescaped, which returns an object which  
> delegates back to the original. On the original Tagz::Document, #\<\<  
> and #concat have the same quoting behavior. On the delegator, they  
> do not quote.

that is kinds of how it works already.

```
   def << string
     case string
       when Document
         super string.to_s
       else
         super XChar.escape(string.to_s)
     end
     self
   end

```

and anything returned by tagz _is_ a document. you can even do

tagz \<\< tagz(‘ not escaped ’)

maybe i’ll just reserver #write of unescaped writing - there needs to  
be one shortcut i think.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
