Re: Trying to create a "view object" with yield self

Berlimioz
2013-06-08T05:59:11Z

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 :

<<-EOF


        #{yield self}

    EOF

the expression "yield self" will here return the return value of the
block
you pass. When you pass a block like this :

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
<!--
first line -->
#{yield self}

EOF

will actually results in something like :

<!--
first line -->
something there


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
> >
> > opening
> > elem1: parent is my-parent
> > elem2: parent is my-parent
> > closing
> >
> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit