Variables-evaluating

----Messaggio originale----
Da: aberger7890@gmail.com
Data: 3-gen-2016

14.02

A: "Ruby users"
Ogg: variables-evaluating

Hello

a='xxx'
print

"Variable a = #{a\t*3}";

does not what I expected
I want ("\t")*3 # three

Tabs

Can this be done in one expression (without print ...., ....) ?

Thank

you

Andrew

Yes, you can do that with a single call to print, but you need two
string interpolations within it:

print "Variable a = #{a}#{"\t"*3}";

I hope
this helps

Stefano

Oh, i didn't see that solution :wink:
But #{x} is too much to write.
is there a possibility within only one #{....} ?

Perhaps there should be an auto-detection for defined vars, so thinks like
print "A=a, B=b"; are possible # => "A=3, B=5" ## a,b declared before, so
can be substituted Idea: special strings => %v(...) for varstring!

What do you think about that? (I cant subscribe to ruby-core ??)

A.

···

Am 03.01.2016 14:13 schrieb "stefano.crocco@alice.it" < stefano.crocco@alice.it>:

>----Messaggio originale----
>Da: aberger7890@gmail.com
>Data: 3-gen-2016
14.02
>A: "Ruby users"
>Ogg: variables-evaluating
>
>Hello
>
>a='xxx'
>print
"Variable a = #{a\t*3}";
>does not what I expected
>I want ("\t")*3 # three
Tabs
>Can this be done in one expression (without print ...., ....) ?
>
>Thank
you
>Andrew

Yes, you can do that with a single call to print, but you need two
string interpolations within it:

print "Variable a = #{a}#{"\t"*3}";

I hope
this helps

Stefano

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Quoting A Berger (aberger7890@gmail.com):

   Oh, i didn't see that solution :wink:
   But #{x} is too much to write.
   is there a possibility within only one #{....} ?

print "Variable a = #{a+"\t"*3}";

Carlo

···

Subject: Re: R: variables-evaluating
  Date: dom 03 gen 16 02:56:42 +0100

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

Ok, " " allowed inside - didnt know that yet! :slight_smile:
But not nested?
print "Variable a = #{a+"\t"*3+#{1+1} }ww";
=> syntax error

···

Am 03.01.2016 16:34 schrieb "Carlo E. Prelz" <fluido@fluido.as>:

        Subject: Re: R: variables-evaluating
        Date: dom 03 gen 16 02:56:42 +0100

Quoting A Berger (aberger7890@gmail.com):

> Oh, i didn't see that solution :wink:
> But #{x} is too much to write.
> is there a possibility within only one #{....} ?

print "Variable a = #{a+"\t"*3}";

Carlo

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hi,

···

In message "Re: R: variables-evaluating" on Sun, 3 Jan 2016 16:49:26 +0100, A Berger <aberger7890@gmail.com> writes:

Ok, " " allowed inside - didnt know that yet! :slight_smile:
But not nested?
print "Variable a = #{a+"\t"*3+#{1+1} }ww";
=> syntax error

Andrew, the community is not your free tutor. Please think before
asking questions to the list. As a rule, extract #{} surrounded code.
In your code a+"\t"*3+#{1+1} is not a valid Ruby code. Remember # is
a comment in Ruby code.

              matz.

Hi Matz, Hi all!

a="xx"
print "Variable a = #{a+"\t"*3+#{1+1} }ww"
(that was my question) is analogous to (working)
print "Variable a = #{a+"\t"*3}";
But its not obvious that nested " are allowed!
I would merely assume that #{ ... #{ ... } } can be used; the code you
quoted is within "...", and therefore could be 'syntactically' correct.
In which cases can I nest "...", can I do it recursively ?
I thought every ' " ' closes the beginning one,
each ' # ' not inside quotes is a comment?
Wherefrom should I know this, please tell me where this is stated.
I asked that in the forum, because its not obvious (tell me, if&why Im
wrong), and I didnt find explanagions in the net.

Thank you,
Berg

···

Am 03.01.2016 19:34 schrieb "Yukihiro Matsumoto" <matz@ruby.or.jp>:

Hi,

In message "Re: R: variables-evaluating" > on Sun, 3 Jan 2016 16:49:26 +0100, A Berger <aberger7890@gmail.com> writes:

>Ok, " " allowed inside - didnt know that yet! :slight_smile:
>But not nested?
>print "Variable a = #{a+"\t"*3+#{1+1} }ww";
>=> syntax error

Please think before asking questions to the list.
As a rule, extract #{} surrounded code.
In your code a+"\t"*3+#{1+1} is not a valid Ruby code. Remember # is
a comment in Ruby code.

                                                        matz.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

#{...} is a block of ruby code embedded in a string. being ruby code it can
contain strings too, and those strings can in turn contain interpolated #{}
blocks. you cannot use #{} in a non-string context. note that once you are
in the #{} block you are no longer in a string context.

martin

···

On Mar 28, 2016 8:19 AM, "A Berger" <aberger7890@gmail.com> wrote:

Hi Matz, Hi all!

a="xx"
print "Variable a = #{a+"\t"*3+#{1+1} }ww"
(that was my question) is analogous to (working)
print "Variable a = #{a+"\t"*3}";
But its not obvious that nested " are allowed!
I would merely assume that #{ ... #{ ... } } can be used; the code you
quoted is within "...", and therefore could be 'syntactically' correct.
In which cases can I nest "...", can I do it recursively ?
I thought every ' " ' closes the beginning one,
each ' # ' not inside quotes is a comment?
Wherefrom should I know this, please tell me where this is stated.
I asked that in the forum, because its not obvious (tell me, if&why Im
wrong), and I didnt find explanagions in the net.

Thank you,
Berg

Am 03.01.2016 19:34 schrieb "Yukihiro Matsumoto" <matz@ruby.or.jp>:
>
> Hi,
>
> In message "Re: R: variables-evaluating" > > on Sun, 3 Jan 2016 16:49:26 +0100, A Berger <aberger7890@gmail.com> > writes:
>
> >Ok, " " allowed inside - didnt know that yet! :slight_smile:
> >But not nested?
> >print "Variable a = #{a+"\t"*3+#{1+1} }ww";
> >=> syntax error
>
> Please think before asking questions to the list.
> As a rule, extract #{} surrounded code.
> In your code a+"\t"*3+#{1+1} is not a valid Ruby code. Remember # is
> a comment in Ruby code.
>
> matz.
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Wherefrom should I know this, please tell me where this is stated.
I asked that in the forum, because its not obvious (tell me, if&why Im

wrong), and I didnt find explanagions in the net.

Thank you,
Berg

Hi,

File: literals.rdoc [Ruby 2.3.0] says:

Double-quote strings allow interpolation of other values using #{...}:

"One plus one is two: #{1 + 1}"

Any expression may be placed inside the interpolated section, but it’s

best to keep the expression small for readability.

It says "any *expression*," so:

~~~ruby
foo = 1

   foo # valid expression
"#{foo}" # valid string => '1'

   #{1} # not an expression
"#{#{1}}" # not a string

   "#{foo}" # valid expression
"#{"#{foo}"}" # valid string => '1'

···

On 29/03/2016 1:20 AM, "A Berger" <aberger7890@gmail.com> wrote:
~~~

Cheers.