[#70977] [Ruby trunk - Feature #11473] Immutable String literal in Ruby 3 — arai@...
Issue #11473 has been updated by Shunichi Arai.
3 messages
2015/10/04
[#70982] limiting scope of magic comments like frozen_string_literal — Eric Wong <normalperson@...>
How about being able to limit the scope of magic comments like
4 messages
2015/10/05
[#71062] [Ruby trunk - Bug #10892] Deadlock in autoload — eregontp@...
Issue #10892 has been updated by Benoit Daloze.
4 messages
2015/10/12
[#71090] Re: [Ruby trunk - Bug #10892] Deadlock in autoload
— Eric Wong <normalperson@...>
2015/10/14
eregontp@gmail.com wrote:
[#71127] [Ruby trunk - Feature #11607] [PATCH] fiddle: release GVL for ffi_call — normalperson@...
Issue #11607 has been updated by Eric Wong.
3 messages
2015/10/20
[#71164] [Ruby trunk - Feature #11614] [Open] [RFC] use id_table for constant tables — normalperson@...
Issue #11614 has been reported by Eric Wong.
3 messages
2015/10/22
[#71211] [Ruby trunk - Feature #11607] [PATCH] fiddle: release GVL for ffi_call — naruse@...
Issue #11607 has been updated by Yui NARUSE.
6 messages
2015/10/27
[#71212] Re: [Ruby trunk - Feature #11607] [PATCH] fiddle: release GVL for ffi_call
— Eric Wong <normalperson@...>
2015/10/27
Yes, user must check if the function is MT-safe. Probably fine
[#71246] Re: [Ruby trunk - Feature #11607] [PATCH] fiddle: release GVL for ffi_call
— Aaron Patterson <tenderlove@...>
2015/10/28
On Tue, Oct 27, 2015 at 08:54:07AM +0000, Eric Wong wrote:
[#71254] Re: [Ruby trunk - Feature #11607] [PATCH] fiddle: release GVL for ffi_call
— Eric Wong <normalperson@...>
2015/10/28
Aaron Patterson <tenderlove@ruby-lang.org> wrote:
[#71230] [Ruby trunk - Feature #11625] Unlock GVL for SHA1 calculations — tenderlove@...
Issue #11625 has been updated by Aaron Patterson.
5 messages
2015/10/27
[#71236] Re: [Ruby trunk - Feature #11625] Unlock GVL for SHA1 calculations
— Юрий Соколов <funny.falcon@...>
2015/10/28
What's about other hashsum algos? MD5, SHA2, etc
[#71242] Re: [Ruby trunk - Feature #11625] Unlock GVL for SHA1 calculations
— Eric Wong <normalperson@...>
2015/10/28
Юрий Соколов <funny.falcon@gmail.com> wrote:
[#71239] [Ruby trunk - Bug #11384] multi-threaded autoload sometimes fails — shugo@...
Issue #11384 has been updated by Shugo Maeda.
4 messages
2015/10/28
[ruby-core:71048] [Ruby trunk - Misc #11495] [Documentation] Please improve documentation for Regexp.new() and clarify the 3 argument call
From:
dylan.pulliam@...
Date:
2015-10-12 00:10:01 UTC
List:
ruby-core #71048
Issue #11495 has been updated by dylan pulliam.
File 0001-Improve-documentation-for-Regexp.new.patch added
Robert A. Heiler wrote:
> The current examples are:
>
> r1 = Regexp.new('^a-z+:\s+\w+') #=> /^a-z+:\s+\w+/
> r2 = Regexp.new('cat', true) #=> /cat/i
> r3 = Regexp.new(r2) #=> /cat/i
> r4 = Regexp.new('dog', Regexp::EXTENDED | Regexp::IGNORECASE) #=> /dog/ix
>
> As you can see, we have examples for one argument, and two arguments given
> but not for three arguments.
>
> Thanks!
Hey Robert,
TL;DR
$KCODE is deprecated and does not affect the use of Regexp at this point. I have a patch ready to go that removes [, kcode] from the doc. That being said I would be happy to modify the patch and just submit an example of using Regexp with 3 parameters.
r5 = Regexp.new('fish', Regexp::IGNORECASE, 'utf8')
The Good Stuff
The kcode parameter in new(string, [options [, kcode]]) or compile(string, [options [, kcode]]) is used to set the global $KCODE variable which basically sets the encoding to be used. This could be UTF-8, Unicode, or any other valid encoding etc.
I believe the example you are looking for would be the following:
r5 = Regexp.new('fish', Regexp::IGNORECASE, 'utf8')
This example is not dependent on the [option] Regexp::IGNORECASE. Any other accepted option should still work with the above example.
However, $KCODE was deprecated in Ruby 1.9 so you will find that setting the encoding does not do anything and you will receive a warning in most cases. You can see this here:
ruby regexp_example.rb
regexp_example.rb:3: warning: encoding option is ignored - utf8
or
irb(main):001:0> Regexp.new('fish', Regexp::IGNORECASE, 'utf8')
(irb):1: warning: encoding option is ignored - utf8
=> /fish/i
However setting the encoding at the console does not provide a warning:
ruby -KU #=> Runs Ruby with UTF-8 encoding
I went ahead and prepared a patch for the documentation. You should be able to find it attached to this comment. I think the best course of action would be to remove [, kcode] since you cannot pass any option that will actually change the outcome. The internal C code will default to ‘n’ or ‘N’ which you can pass in without warning but basically just says “don’t specify encoding just treat as binary string”. That being said since it was deprecated I would be happy to modify the patch and just add the example for now.
If you would like more information on regular expressions and kcodes in ruby
go ahead and checkout the following links. They helped a lot when I was
researching this topic.
http://nuclearsquid.com/writings/ruby-1-9-what-s-new-what-s-changed/
http://graysoftinc.com/character-encodings/the-kcode-variable-and-jcode-library
https://www.ruby-forum.com/topic/178589
http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/
----------------------------------------
Misc #11495: [Documentation] Please improve documentation for Regexp.new() and clarify the 3 argument call
https://bugs.ruby-lang.org/issues/11495#change-54419
* Author: Robert A. Heiler
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Hello,
The documentation at Regepx.new here:
http://ruby-doc.org/core-2.2.3/Regexp.html#method-c-new
It shows a lot of information, in particular four ways to call it:
new(string, [options [, kcode]]) -> regexp
new(regexp) -> regexp
compile(string, [options [, kcode]]) -> regexp
compile(regexp) -> regexp
However, the examples given do not show an example of where
3 arguments are passed.
Today this came up on IRC where someone asked how to use
respectively what the meaning of kcode is, via example.
Can someone add an example of where/when to use 3 arguments
to this method please? Thank you.
---Files--------------------------------
0001-Improve-documentation-for-Regexp.new.patch (1.55 KB)
--
https://bugs.ruby-lang.org/