[Rails] Re: Trying to create a "view object" with yield self
Ok, maybe this could help :
When your method initialize returns a string, calling Accordion.new doesn't return this string, because the initialize method is called in the new method, but that's not what's returned by the new class method.
On the other hand, when you have this :
the expression "yield self" will here return the return value of the block you pass. When you pass a block like this :<<-EOF<div class="accordion" id="#{@parent_id}"> <!-- first line -->#{yield self}</div> <!-- last line -->EOF
Accordion.new() do |accordion|
"something here"
"something there"
end
the return value of the block is only "something there" (last line of the block). So that
<<-EOF
<div class="accordion" id="#{@parent_id}"> <!-- first line -->
#{yield self}
</div> <!-- last line -->
EOF
will actually results in something like :
<div class="accordion" id="#{@parent_id}"> <!-- first line -->
something there
</div> <!-- last line -->
Hope it helped, enjoy your week end anyway !
Le vendredi 7 juin 2013 23:31:01 UTC+2, Ruby-Forum.com User a écrit :
Berlimioz wrote in post #1111637:
> Hi pry_f !
>
> Sorry but I'm not sure to have exactly understood what you're trying to
> do.
> What I understand from the code you made available is that the lines
> below
> should display something like
>
> <p>opening</p>
> <li> elem1: parent is my-parent</li>
> <li> elem2: parent is my-parent</li>
> <p>closing</p>
>
> and it doesn't ?
>
> Le jeudi 6 juin 2013 19:48:46 UTC+2, Ruby-Forum.com User a crit :
That's right. This is not a model related problem. I'm trying
to make view "widgets" basically.
I created another gist. This time it's just a ruby script demonstrating
the concept by printing to standard out.
https://gist.github.com/PryFlack/5732422
I have a little bug as mentioned in the comment. I was pretty sure this
was going to work in plain ruby. Anyways with rails I've had trouble
implementing this idea even more. I don't see how I could use partials
for that so the only thing I can think of is what I'm doing here. Thanks
for your feedback and interest !
--
Posted via http://www.ruby-forum.com/.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/813380d2-a8fb-4f28-989b-176693aebab8%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home