# Behavior vs. Context

**URL:** <https://www.ruby-forum.com/t/behavior-vs-context/100197>\
**Category:** Radiant CMS\
**Created:** [July 27, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/behavior-vs-context/100197 "2006-07-27T18:11:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 27, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/behavior-vs-context/100197/1 "2006-07-27T18:11:29Z")

</div>

John et al,

In an effort to extend Radiant for my own needs, I have discovered that  
I  
need to create some Radius tags. Ideally, I’d like these to be part of  
the  
PageContext class, but I’m not sure how to go about it (should I  
alias/override initialize?). I’d be willing to settle for a behavior,  
but  
since a page can only have a single behavior, and the tags are more like  
utilities, I’m not sure it’s appropriate. How should I proceed? Are  
there  
best practices for this sort of thing?

TIA

Sean C.  
[seancribbs.com](http://seancribbs.com)

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 27, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/behavior-vs-context/100197/2 "2006-07-27T18:17:58Z")

</div>

Sean C. wrote:

> John et al,
> 
> In an effort to extend Radiant for my own needs, I have discovered that  
> I need to create some Radius tags. Ideally, I’d like these to be part  
> of the PageContext class, but I’m not sure how to go about it (should I  
> alias/override initialize?). I’d be willing to settle for a behavior,  
> but since a page can only have a single behavior, and the tags are more  
> like utilities, I’m not sure it’s appropriate. How should I proceed?  
> Are there best practices for this sort of thing?

I’ve been doing this via a plugin, as follows:

class Behavior::Base  
define\_tags do  
tag “slicktabs” do |tag|  
slicktab = SlickTabs.new(tag)  
slicktab.output  
end  
…other tags…  
end  
end

class SlickTabs  
…  
end

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 28, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/behavior-vs-context/100197/3 "2006-07-28T16:29:34Z")

</div>

Sean C. wrote:

> ```
> end
> 
> class SlickTabs
> ...
> end
> 
> ```
> 
> So essentially, Behavior::Base is available whether there’s a behavior  
> assigned or not? Or am I misunderstanding?

I just wrote a whole screed about reopening classes in Ruby, then  
realized you were asking if Behavior::Base is always available -to the  
page-. Oops.

From experience, yes - you don’t need a behavior defined to use the  
tags you call from Behavior::Base. I’m not sure entirely why; John can  
shed some light, I’m sure.

I think it’s because Behavior::Base acts as kind of an abstract base  
class - it sets up a bunch of helpers for defining tags, but (normally)  
doesn’t call any of them itself. Any behaviors you write would descend  
from it and call them. And Page seems to delegate to Behavior no matter  
what, so if no other behavior is defined, you’re still getting  
Behavior::Base, which normally does nothing. Now that you’ve reopened  
it, you’re defining some tags as well - you’ve modified the “nil”  
behavior.

I’m very muddy on this advanced\_delegation stuff, so my explanation of  
WHY it works may be totally wrong. But it works. Just like a cargo  
cult.

Jay

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 28, 2006, 3:52pm UTC](https://www.ruby-forum.com/t/behavior-vs-context/100197/4 "2006-07-28T15:52:05Z")

</div>

> end  
> end
> 
> class SlickTabs  
> …  
> end

So essentially, Behavior::Base is available whether there’s a behavior  
assigned or not? Or am I misunderstanding?
