Substitute

Hello
short question:
Is there a way to downcase a string without executing a block
- Like in perl: \Lstring

x="abc"
sg like $_.gsub(x, "\L$1") .... instead gsub((x)){$1.downcase}

Thx Berg

Dude, are you kidding? I'm not even going to paste a link. Try harder.

···

On Wed, Sep 21, 2016 at 11:23 AM A Berger <aberger7890@gmail.com> wrote:

Hello
short question:
Is there a way to downcase a string without executing a block
- Like in perl: \Lstring

x="abc"
sg like $_.gsub(x, "\L$1") .... instead gsub((x)){$1.downcase}

Thx Berg

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

--

- Raj

Hi
I didnt find a solution,
so I ask, if there is a way.
A simple "not possible" would be a nice answer. (Not finding anything,
doesnt mean, there is no way!)

Thx Berg

···

Am 21.09.2016 21:05 schrieb "Raj Sahae" <rajsahae@gmail.com>:

Dude, are you kidding? I'm not even going to paste a link. Try harder.

On Wed, Sep 21, 2016 at 11:23 AM A Berger <aberger7890@gmail.com> wrote:

Hello
short question:
Is there a way to downcase a string without executing a block
- Like in perl: \Lstring

x="abc"
sg like $_.gsub(x, "\L$1") .... instead gsub((x)){$1.downcase}

Thx Berg

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

--

- Raj

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

Hey, unless I misunderstand, I think Raj was suggesting you look at Ruby
differently than Perl.

"ABC".downcase # Gives "abc"

Leam

···

On Wed, Sep 21, 2016 at 3:25 PM, A Berger <aberger7890@gmail.com> wrote:

Hi
I didnt find a solution,
so I ask, if there is a way.
A simple "not possible" would be a nice answer. (Not finding anything,
doesnt mean, there is no way!)

Thx Berg
Am 21.09.2016 21:05 schrieb "Raj Sahae" <rajsahae@gmail.com>:

Dude, are you kidding? I'm not even going to paste a link. Try harder.

On Wed, Sep 21, 2016 at 11:23 AM A Berger <aberger7890@gmail.com> wrote:

Hello
short question:
Is there a way to downcase a string without executing a block
- Like in perl: \Lstring

x="abc"
sg like $_.gsub(x, "\L$1") .... instead gsub((x)){$1.downcase}

Thx Berg

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

--

- Raj

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;

--
Mind on a Mission <http://leamhall.blogspot.com/&gt;

Hi
yes, but how to change only special patterns (-> gsub) ?
\L is much easier then {...}

Bye Berg

···

Am 21.09.2016 21:29 schrieb "leam hall" <leamhall@gmail.com>:

Hey, unless I misunderstand, I think Raj was suggesting you look at Ruby
differently than Perl.

"ABC".downcase # Gives "abc"

Leam

On Wed, Sep 21, 2016 at 3:25 PM, A Berger <aberger7890@gmail.com> wrote:

Hi
I didnt find a solution,
so I ask, if there is a way.
A simple "not possible" would be a nice answer. (Not finding anything,
doesnt mean, there is no way!)

Thx Berg
Am 21.09.2016 21:05 schrieb "Raj Sahae" <rajsahae@gmail.com>:

Dude, are you kidding? I'm not even going to paste a link. Try harder.

On Wed, Sep 21, 2016 at 11:23 AM A Berger <aberger7890@gmail.com> wrote:

Hello
short question:
Is there a way to downcase a string without executing a block
- Like in perl: \Lstring

x="abc"
sg like $_.gsub(x, "\L$1") .... instead gsub((x)){$1.downcase}

Thx Berg

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

--

- Raj

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;

--
Mind on a Mission <http://leamhall.blogspot.com/&gt;

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

Hi,

···

On 2016/09/22 4:37, A Berger wrote:

Hi
yes, but how to change only special patterns (-> gsub) ?
\L is much easier then {...}

I don't know what \L means in Perl, but how's this?

[1] pry(main)> "ABCDEF".gsub(/CD/, &:downcase)
=> "ABcdEF"
[2] pry(main)>

Toshi

Toshi, nice! I didn't know about that!

···

###
On Wed, Sep 21, 2016 at 4:41 PM, Toshihiko Ichida <dogatana@gmail.com> wrote:

[1] pry(main)> "ABCDEF".gsub(/CD/, &:downcase)
=> "ABcdEF"
[2] pry(main)>

Toshi
###

Mind on a Mission <http://leamhall.blogspot.com/>

It's basically shorthand for passing a block. Just like how you could say

  ["foo", "bar"].map(&:upcase)

rather than

  ["foo", "bar"].map { |str| str.upcase }

···

On Wed, Sep 21, 2016 at 5:08 PM, leam hall <leamhall@gmail.com> wrote:

Toshi, nice! I didn't know about that!

###
On Wed, Sep 21, 2016 at 4:41 PM, Toshihiko Ichida <dogatana@gmail.com> > wrote:

[1] pry(main)> "ABCDEF".gsub(/CD/, &:downcase)
=> "ABcdEF"

--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.

It's the same principle as some_array_of_strings.map(&:downcase), that is,
it leverages the "&:" shortcut which uses an implicit call to
Symbol#to_proc method. You are still using a block/proc but the syntactic
sugar makes it much less verbose to type.

···

On Wed, Sep 21, 2016 at 2:08 PM leam hall <leamhall@gmail.com> wrote:

Toshi, nice! I didn't know about that!

###
On Wed, Sep 21, 2016 at 4:41 PM, Toshihiko Ichida <dogatana@gmail.com> > wrote:

[1] pry(main)> "ABCDEF".gsub(/CD/, &:downcase)
=> "ABcdEF"
[2] pry(main)>

Toshi
###

Mind on a Mission <http://leamhall.blogspot.com/&gt;

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

--

- Raj

Hi!

thats the solution I was looking for -
nowhere declared, that the block can be given as second param.
Thanks to Toshi!

Berg

But looks like there is no way to cascade that?
like \L\U => ...(&:downcase.&:upcase)

(ok, not a very useful example... :slight_smile:
Cheers Berg

Hi,

But looks like there is no way to cascade that?
like \L\U => ...(&:downcase.&:upcase)

(ok, not a very useful example... :slight_smile:

Unfortunately, not..

In that case we need to use a block or a proc object.

If you
- want to simply process the matched data with applying methods
- call sub/gsub many times
using a proc object may save your time :slight_smile:

[4] pry(main)> p = ->(x) { x.downcase.upcase }
=> #<Proc:0x546a5d8@(pry):4 (lambda)>
[5] pry(main)> "AbCdEf".sub(/Cd/, &p)
=> "AbCDEf"
[6] pry(main)> "GhIjKl".sub(/Ij/, &p)
=> "GhIJKl"

···

On 2016/09/22 16:51, A Berger wrote:

--
Toshi