[#66678] [ruby-trunk - Feature #10481] Add "if" and "unless" clauses to rescue statements — alex@...
Issue #10481 has been updated by Alex Boyd.
3 messages
2014/12/04
[#66762] Re: [ruby-changes:36667] normal:r48748 (trunk): struct: avoid all O(n) behavior on access — Tanaka Akira <akr@...>
2014-12-10 0:44 GMT+09:00 normal <ko1@atdot.net>:
3 messages
2014/12/10
[#66851] [ruby-trunk - Feature #10585] struct: speedup struct.attr = v for first 10 attributes and struct[:attr] for big structs — funny.falcon@...
Issue #10585 has been updated by Yura Sokolov.
3 messages
2014/12/15
[#67126] Ruby 2.2.0 Released — "NARUSE, Yui" <naruse@...>
We are pleased to announce the release of Ruby 2.2.0.
8 messages
2014/12/25
[#67128] Re: Ruby 2.2.0 Released
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2014/12/25
I can't install it in any of our Ubuntu servers using rbenv:
[#67129] Re: Ruby 2.2.0 Released
— SHIBATA Hiroshi <shibata.hiroshi@...>
2014/12/25
> I can't install it in any of our Ubuntu servers using rbenv:
[ruby-core:67057] [ruby-trunk - Feature #7883] Add Regex#to_proc
From:
nobu@...
Date:
2014-12-23 03:09:03 UTC
List:
ruby-core #67057
Issue #7883 has been updated by Nobuyoshi Nakada.
Description updated
Nothing, and line 10 is possible with `grep`
~~~ruby
%w{foo bar baz}.grep(/\Ab/) {|s|break s}
~~~
Anyway, a patch.
~~~diff
diff --git i/re.c w/re.c
index 1a0f0b1..d345f17 100644
--- i/re.c
+++ w/re.c
@@ -801,6 +801,19 @@ rb_reg_named_captures(VALUE re)
return hash;
}
+static VALUE
+rb_reg_to_proc(VALUE re)
+{
+ const ID id = 1;
+ VALUE proc = rb_attr_get(re, id);
+ if (NIL_P(proc)) {
+ proc = rb_obj_method(re, ID2SYM(rb_intern("=~")));
+ proc = rb_funcall(proc, rb_intern("to_proc"), 0, 0);
+ rb_ivar_set(re, id, proc);
+ }
+ return proc;
+}
+
static int
onig_new_with_source(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax,
@@ -3660,6 +3673,7 @@ Init_Regexp(void)
rb_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0);
rb_define_method(rb_cRegexp, "names", rb_reg_names, 0);
rb_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0);
+ rb_define_method(rb_cRegexp, "to_proc", rb_reg_to_proc, 0);
/* see Regexp.options and Regexp.new */
rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
~~~
----------------------------------------
Feature #7883: Add Regex#to_proc
https://bugs.ruby-lang.org/issues/7883#change-50575
* Author: Robert Klemme
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: next minor
----------------------------------------
Just a small addition to the standard library:
~~~ruby
class Regexp
def to_proc; lambda {|s| self =~ s} end
end
~~~
With that one can use a `Regexp` everywhere a `Proc` is used as filtering criteria saving a bit of typing. While we have `Enumerable#grep` already there may be other cases where you want to do something like
~~~ruby
irb(main):008:0> %w{foo bar baz}.select &/\Ab/
=> ["bar", "baz"]
irb(main):009:0> %w{foo bar baz}.reject &/\Ab/
=> ["foo"]
irb(main):010:0> %w{foo bar baz}.find &/\Ab/
=> "bar"
~~~
Note: line 9 and 10 are not possible with `Enumerable#grep` AFAIK.
I see low risk of breaking something.
--
https://bugs.ruby-lang.org/