%myOwn

Hi
I miss sg like the perl quoting shorcuts, wanting to create an array of
words without , and "
e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
in a short form (%Q, but without split)
=> Can I define my own %y(....) ?

Thanks
Andrew

Andres,

···

On Wednesday 06 January 2016 23:47:03, A Berger <aberger7890@gmail.com> wrote:

I miss sg like the perl quoting shorcuts, wanting to create an array of

words without , and "
e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
in a short form (%Q, but without split)

the qw(...) construct of Perl is available in Ruby, too, as %w(word1 token2
thingy3).

HTH.

      --- Eric

Can you PLEASE check a reference, ANY reference, before posting questions here? I minimum of research isn't too much to ask. Even Matz asked this of you and you seem to be ignoring the suggestion.

Start with the ruby quickref (Ruby | zenspider.com | by ryan davis)

···

On Jan 6, 2016, at 14:47, A Berger <aberger7890@gmail.com> wrote:

I miss sg like the perl quoting shorcuts, wanting to create an array of words without , and "
e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
in a short form (%Q, but without split)
=> Can I define my own %y(....) ?

Hi
but I need the "" too, and
%w %Q (a b c) is only one string
(The string is the problem)
A

···

Am 06.01.2016 23:50 schrieb "Eric MSP Veith" <eveith@wwweb-library.net>:

Andres,

On Wednesday 06 January 2016 23:47:03, A Berger <aberger7890@gmail.com> > wrote:
>> I miss sg like the perl quoting shorcuts, wanting to create an array of
> words without , and "
> e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
> in a short form (%Q, but without split)

the qw(...) construct of Perl is available in Ruby, too, as %w(word1 token2
thingy3).

HTH.

                        --- Eric

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

%w creates a list of double quoted strings:
%w(a b c) => ["a", "b", "c"]

I'm not sure what you're looking for that isn't provided by that.

···

On Wed, Jan 6, 2016 at 3:13 PM A Berger <aberger7890@gmail.com> wrote:

Hi
but I need the "" too, and
%w %Q (a b c) is only one string
(The string is the problem)

A
Am 06.01.2016 23:50 schrieb "Eric MSP Veith" <eveith@wwweb-library.net>:

Andres,

On Wednesday 06 January 2016 23:47:03, A Berger <aberger7890@gmail.com> >> wrote:
>> I miss sg like the perl quoting shorcuts, wanting to create an array of
> words without , and "
> e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
> in a short form (%Q, but without split)

the qw(...) construct of Perl is available in Ruby, too, as %w(word1
token2
thingy3).

HTH.

                        --- Eric

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;

I see!
Maybe I've written %w(1,2,3) which makes a one string-array
- My mistake
Nevertheless can this be redefined (for numbers / own method for mixed
num/strings)?

Thank you
A.

···

Am 07.01.2016 00:18 schrieb "James Pacheco" <james.pacheco@gmail.com>:

%w creates a list of double quoted strings:
%w(a b c) => ["a", "b", "c"]

I'm not sure what you're looking for that isn't provided by that.

On Wed, Jan 6, 2016 at 3:13 PM A Berger <aberger7890@gmail.com> wrote:

Hi
but I need the "" too, and
%w %Q (a b c) is only one string
(The string is the problem)

A
Am 06.01.2016 23:50 schrieb "Eric MSP Veith" <eveith@wwweb-library.net>:

Andres,

On Wednesday 06 January 2016 23:47:03, A Berger <aberger7890@gmail.com> >>> wrote:
>> I miss sg like the perl quoting shorcuts, wanting to create an array
of
> words without , and "
> e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
> in a short form (%Q, but without split)

the qw(...) construct of Perl is available in Ruby, too, as %w(word1
token2
thingy3).

HTH.

                        --- Eric

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;

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

Note that the phrasing is misleading: the String instances created do not
contain quotes. You only see the quotes because of the output method
(#inspect or p() most likely). And you cannot use string interpolation
within this construct which you can in double quoted strings.

Cheers

robert

···

On Thu, Jan 7, 2016 at 12:18 AM, James Pacheco <james.pacheco@gmail.com> wrote:

%w creates a list of double quoted strings:

I think its hard-coded -- ok method without % will also do it.
But %a would be nicer than %w (why %w ?? )
A.

No, those perl-like regexp-like constructs are tightly integrated with the
ruby parser, so can't be extended from within ruby. The best bet would be
to use #map, #reject, etc. For example:

    %w(1 2 three 4).map{|s| s =~ /^\d+$/ ? s.to_i : s }
    # => [1, 2, "three", 4]

You could always monkey-patch methods onto Array, so you could write:

    %w( 1 2 three 4 ).numericalize

...or whatever.

Cheers

···

On 7 January 2016 at 09:38, A Berger <aberger7890@gmail.com> wrote:

I see!
Maybe I've written %w(1,2,3) which makes a one string-array
- My mistake
Nevertheless can this be redefined (for numbers / own method for mixed
num/strings)?

Thank you
A.
Am 07.01.2016 00:18 schrieb "James Pacheco" <james.pacheco@gmail.com>:

%w creates a list of double quoted strings:
%w(a b c) => ["a", "b", "c"]

I'm not sure what you're looking for that isn't provided by that.

On Wed, Jan 6, 2016 at 3:13 PM A Berger <aberger7890@gmail.com> wrote:

Hi
but I need the "" too, and
%w %Q (a b c) is only one string
(The string is the problem)

A
Am 06.01.2016 23:50 schrieb "Eric MSP Veith" <eveith@wwweb-library.net>:

Andres,

On Wednesday 06 January 2016 23:47:03, A Berger <aberger7890@gmail.com> >>>> wrote:
>> I miss sg like the perl quoting shorcuts, wanting to create an array
of
> words without , and "
> e.g. qw(abc d 1 e) # => ["abc", "d", 1, "e"]
> in a short form (%Q, but without split)

the qw(...) construct of Perl is available in Ruby, too, as %w(word1
token2
thingy3).

HTH.

                        --- Eric

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;

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;

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Matthew: you mean %q/..../ ?
is here /..../ the same as () ?
What does %/.../ do ?

Yes the beginning problem I was looking for was a text-output including the
"...." - thats the difference to perl.

Thanks for that many answers!
A.

%w creates a list of double quoted strings:

Note that the phrasing is misleading: the String instances created do not

contain quotes. You only see the quotes because of the output method
(#inspect or p() most likely). And you cannot use string interpolation
within this construct which you can in double quoted strings.

···

Am 07.01.2016 09:37 schrieb "Robert Klemme" <shortcutter@googlemail.com>:

On Thu, Jan 7, 2016 at 12:18 AM, James Pacheco <james.pacheco@gmail.com> wrote:

Cheers

robert

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

You definitely can use interpolation in some of the forms. From the quickref:

%q(no interpolation)
%Q(interpolation and backslashes)
%(interpolation and backslashes)
%x(echo command interpretation with interpolation and backslashes)
%w(foo bar baz #{1+1}) == ["foo", "bar", "baz", "\#{1+1}"]
%W(foo bar baz #{1+1}) == ["foo", "bar", "baz", "2"]

···

On Jan 7, 2016, at 00:37, Robert Klemme <shortcutter@googlemail.com> wrote:

Note that the phrasing is misleading: the String instances created do not contain quotes. You only see the quotes because of the output method (#inspect or p() most likely). And you cannot use string interpolation within this construct which you can in double quoted strings.

​From perl: perlop - Perl operators and precedence - Perldoc Browser

    #perl ruby result mnemonic
    #---- ---- ------ --------
    q/a\nb/ %/a\nb/ "a\nb" # string ("...")
    ​qq/a\nb/ %q/a\nb/ ​"a\\nb" # (single-)quoted string ('...')
    qx/ls/ %x/ls/ ".\n..\n" # executed (`...`)
    qw/a b/ %w/a b/ ["a", "b"] # words

(Note that you can use paired symbols like "/.../" or matched pairs like
"(...)" in both languages)

Cheers

···

On 7 January 2016 at 09:48, A Berger <aberger7890@gmail.com> wrote:

I think its hard-coded -- ok method without % will also do it.
But %a would be nicer than %w (why %w ?? )
A.

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Thanks for that many answers!

You're welcome. If you do not trim quotes please make at least sure you
reply to the message that you are actually intending to reply to.

···

On Thu, Jan 7, 2016 at 10:18 AM, A Berger <aberger7890@gmail.com> wrote:

Am 07.01.2016 09:37 schrieb "Robert Klemme" <shortcutter@googlemail.com>:

Cheers

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can -
without end}
http://blog.rubybestpractices.com/

Matthew: you mean %q/..../ ?

​I meant exactly what I wrote.​

is here /..../ the same as () ?

​Let me copy-and-paste what I wrote in my email: Note that you can use
paired symbols like "/.../" or matched pairs like "(...)" in both languages​

What does %/.../ do ?

​Just like I said, it's ruby's equivalent of perl's q/.../. I even gave an
example.​

Yes the beginning problem I was looking for was a text-output including
the "...." - thats the difference to perl.

​No, you were asking for something like perl's qw/.../ and we told you that
ruby provides %w/.../​


If you want help with output, there are options like these:

    puts foo.inspect

    p foo

    require 'pp'
    pp foo

Thanks for that many answers!

A.​

​No worries, but please do make an effort to read and understand them. If
something's unclear, try it for yourself. 'irb' is a very handy tool for
this.​

···

On 7 January 2016 at 19:18, A Berger <aberger7890@gmail.com> wrote:

--
  Matthew Kerwin
​​
  http://matthew.kerwin.net.au/

Hi Ryan!
I already have bought RubyRef by Fitzgerald. -- No %(), no %W, no %//
Seems this cannot be recommended (bought both, version 1.8 (2007) is better
than 2.2 (2015), altogether not uptodate.
goggle didnt find anything with ruby + %()..
( - or I used the wrong search text)
Because I owned the "best rated" refs already, I didnt search for Refs.
I had a long way suffering using that Reference from Fitzgerald. - cant
understand why 1st version looks more complete then the 2nd one.
So I say thanks for this html-ref ( the layout is not the best, but the
contents count; and its free)
ABerger

···

Am 08.01.2016 01:06 schrieb "Ryan Davis" <ryand-ruby@zenspider.com>:

> On Jan 7, 2016, at 00:37, Robert Klemme <shortcutter@googlemail.com> > wrote:
>
> Note that the phrasing is misleading: the String instances created do
not contain quotes. You only see the quotes because of the output method
(#inspect or p() most likely). And you cannot use string interpolation
within this construct which you can in double quoted strings.

You definitely can use interpolation in some of the forms. From the
quickref:

%q(no interpolation)
%Q(interpolation and backslashes)
%(interpolation and backslashes)
%x(echo command interpretation with interpolation and backslashes)
%w(foo bar baz #{1+1}) == ["foo", "bar", "baz", "\#{1+1}"]
%W(foo bar baz #{1+1}) == ["foo", "bar", "baz", "2"]

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

Ryan, I was specifically referring to %w (meant by "this construct") which
you removed in your quote.

Cheers

robert

···

On Fri, Jan 8, 2016 at 1:06 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

> On Jan 7, 2016, at 00:37, Robert Klemme <shortcutter@googlemail.com> > wrote:
>
> Note that the phrasing is misleading: the String instances created do
not contain quotes. You only see the quotes because of the output method
(#inspect or p() most likely). And you cannot use string interpolation
within this construct which you can in double quoted strings.

You definitely can use interpolation in some of the forms. From the
quickref:

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can -
without end}
http://blog.rubybestpractices.com/

But only irb 1.9 here.

Why? What's the point of "learning" an obsolete version of a language?

Why is Ruby 2.3 binaries size (Intel x86) 10 times of Ruby 1.9 (defaults for
compiling, stripped)??

?? Installed on an Intel Mac via rvm:

07:51 ~/.rvm/rubies[ruby-2.2.4]$ du -sh ruby-1.9.2-p330/
20M ruby-1.9.2-p330/
07:51 ~/.rvm/rubies[ruby-2.2.4]$ du -sh ruby-2.2.4/
33M ruby-2.2.4/

Doesn't seem like a significant issue to me. Regardless, I'd certainly
recommend upgrading to a supported version.

···

On Thu, Jan 7, 2016 at 7:41 AM, A Berger <aberger7890@gmail.com> wrote:

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan
Consulting Availability : Silicon Valley or remote

Hi!

Matthew: you mean %q/..../ ?

​I meant exactly what I wrote.​

is here /..../ the same as () ?

​Let me copy-and-paste what I wrote in my email: Note that you can use

paired symbols like "/.../" or matched pairs like "(...)" in both languages​

So %/..../ seems to be the same as %Q/..../
ok next day I shouldn't answer (on the mobile) when I dont have the time
for it.

What does %/.../ do ?

​Just like I said, it's ruby's equivalent of perl's q/.../. I even gave

an example.​

() is the 'same' as //, but I didnt knew %()
(where is that documented - I have found it nowhere but most books are of
v1.8 and v1.9)?

Yes the beginning problem I was looking for, was a text-output including

the "...." - thats the difference to perl.

​No, you were asking for something like perl's qw/.../ and we told you

that ruby provides %w/.../​

the beginning of my tests, before I put the resulting question here, so I
then remembered what the origin of my questions was

If you want help with output, there are options like these:

    puts foo.inspect

    p foo

    require 'pp'
    pp foo

thanks for pp. Also new to me!

​No worries, but please do make an effort to read and understand them. If

something's unclear, try it for yourself. 'irb' is a very handy tool for
this.​
But only irb 1.9 here.
Why is Ruby 2.3 binaries size (Intel x86) 10 times of Ruby 1.9 (defaults
for compiling, stripped)??

ok :slight_smile:
ABerger

···

Am 07.01.2016 10:51 schrieb "Matthew Kerwin" <matthew@kerwin.net.au>:

On 7 January 2016 at 19:18, A Berger <aberger7890@gmail.com> wrote:

  Matthew Kerwin
​​
  http://matthew.kerwin.net.au/

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

So %/..../ seems to be the same as %Q/..../

Yes, that's correct. Incidentally, if you use a more current version lf
ruby there's also %i(...) which evaluates to an array of symbols. (I think
this may have been mentioned up-thread.)

() is the 'same' as //, but I didnt knew %()
(where is that documented - I have found it nowhere but most books are of

v1.8 and v1.9)?

http://ruby-doc.org/core-2.3.0/doc/syntax/literals_rdoc.html#label-Percent+Strings

http://docs.ruby-lang.org/en/2.0.0/syntax/literals_rdoc.html#label-Percent+Strings

Etc.

I'm quite certain it's in the 1.8 and 1.9.2/1.9.3 docs (or books)
somewhere, too, because I had to have learned about it somewhere.

<snip>

> If you want help with output, there are options like these:
>
> puts foo.inspect
>
> p foo
>
> require 'pp'
> pp foo

thanks for pp. Also new to me!

You can remember it as 'Pretty Print'

>
> ​No worries, but please do make an effort to read and understand them.

If something's unclear, try it for yourself. 'irb' is a very handy tool for
this.​

But only irb 1.9 here.

I've used these since at least ruby 1.8 :wink:

(Except for %i, which I've never had to use)

···

On 08/01/2016 1:42 AM, "A Berger" <aberger7890@gmail.com> wrote:

Google doesn't deal well with non-alphanumeric characters in searches.
http://symbolhound.com/ is the resource I use for searching for things like
%(). Unfortunately, though, in the past the site has sometimes failed to
bring up any results for my searches, but then when I tried a few days
later everything worked fine. I hope they've improved their reliability now.

···

On Fri, Jan 8, 2016 at 12:49 AM, A Berger <aberger7890@gmail.com> wrote:

goggle didnt find anything with ruby + %()..
( - or I used the wrong search text)

--
        Eric Christopherson