Forum: Ruby Is there any difference between ERB#run and ERB#result

249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-03-15 19:55
I am wondering if there is any difference between
http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/E...
and
http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/E....
Is there any ?

I am reading - http://rrn.dk/rubys-erb-templating-system and
http://apidock.com/ruby/ERB .. Didn't find any difference.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (fxn)
on 2014-03-15 20:10
(Received via mailing list)
On Sat, Mar 15, 2014 at 7:55 PM, Arup Rakshit <lists@ruby-forum.com>
wrote:

I am wondering if there is any difference between
> http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/E...
> and
> http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/E....
> Is there any ?
>


Click the toggler to see the source code.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-03-15 20:47
Xavier Noria wrote in post #1139990:
> On Sat, Mar 15, 2014 at 7:55 PM, Arup Rakshit <lists@ruby-forum.com>
> wrote:

>
>
> Click the toggler to see the source code.

Humm.. Xavier. I did it.. #run calling #result inside it. No idea, why
then `#run` is needed in the API. That's a my question. Because in CSV
module, I found lot's of such things, where docs saying same, but they
are not. I found 1 bug, and some other wrong documentation. Verified by
JEGII, who used to tell you **Ruby Hero** :-)
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (fxn)
on 2014-03-15 20:58
(Received via mailing list)
On Sat, Mar 15, 2014 at 8:47 PM, Arup Rakshit <lists@ruby-forum.com>
wrote:

Xavier Noria wrote in post #1139990:
> are not. I found 1 bug, and some other wrong documentation. Verified by
> JEGII, who used to tell you **Ruby Hero** :-)
>

Yeah, you could just remove the method, but having the method is equally
valid.

Sometimes libraries have convenience methods like that, in Perl land for
example this one-liner is legendary:

    perl -MLWP::Simple -e 'getprint "http://www.sn.no"'

Why getprint? Well, no big deal, the author just wanted to provide the
shortcut.

ERB and CSV have nothing to do, their APIs may not be coherent between
each
other, but that's not their goal, if that is true that's fine, it is
apples
and oranges.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-03-15 21:05
Xavier Noria wrote in post #1139992:
> On Sat, Mar 15, 2014 at 8:47 PM, Arup Rakshit <lists@ruby-forum.com>
> wrote:

> ERB and CSV have nothing to do, their APIs may not be coherent between
> each
> other, but that's not their goal, if that is true that's fine, it is
> apples
> and oranges.

I know they are different library .. I meant to say, currently I am not
taking any risks.. :-) May be something there between those 2 methods
(#run and #result), but not documented. So I asked here to experts, if
they have anything to share.. :-)
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (fxn)
on 2014-03-15 21:20
(Received via mailing list)
On Sat, Mar 15, 2014 at 9:05 PM, Arup Rakshit <lists@ruby-forum.com>
wrote:

I know they are different library .. I meant to say, currently I am not
> taking any risks.. :-) May be something there between those 2 methods
> (#run and #result), but not documented.


I guess there is a misunderstanding somewhere, ERB#run says in its
documentation that it prints the result.

Maybe you interpret something else due to some issue with the English
sentence?
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-03-15 21:27
Xavier Noria wrote in post #1139995:
> On Sat, Mar 15, 2014 at 9:05 PM, Arup Rakshit <lists@ruby-forum.com>
> wrote:
>
> I guess there is a misunderstanding somewhere, ERB#run says in its
> documentation that it prints the result.
>
> Maybe you interpret something else due to some issue with the English
> sentence?

I got it now they will work same way ( only 2 doors for the same room ),
as you involved.. :-)

Thank you very much for your time as always.
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2014-03-16 03:45
(Received via mailing list)
On Sat, Mar 15, 2014 at 3:27 PM, Arup Rakshit <lists@ruby-forum.com>
wrote:
> I got it now they will work same way ( only 2 doors for the same room ),
> as you involved.. :-)

No, they are different.

run *calls* result and *prints* it, as in displays it on STDOUT.

result merely returns the processed input as a string.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-03-16 10:28
tamouse m. wrote in post #1140013:
> On Sat, Mar 15, 2014 at 3:27 PM, Arup Rakshit <lists@ruby-forum.com>

> No, they are different.
>
> run *calls* result and *prints* it, as in displays it on STDOUT.
>
> result merely returns the processed input as a string.

Yes,,, In my case I was using `puts` with both, thus couldn't catch the
difference. Now I tried as you said, got the difference :

#run

require 'erb'

name = "Arup" # !> assigned but unused variable - name
template_string = "My name is <%= name %>"
template = ERB.new template_string
template.run
# >> My name is Arup

#result

require 'erb'

name = "Arup" # !> assigned but unused variable - name
template_string = "My name is <%= name %>"
template = ERB.new template_string
template.result # no output.

Thank you very much.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.