diff --git a/array.rb b/array.rb index 81beff0b1c4016..f45e6a0d5e5ade 100644 --- a/array.rb +++ b/array.rb @@ -283,5 +283,23 @@ def select # :nodoc: alias filter select end end + + if Primitive.rb_builtin_basic_definition_p(:find) + undef :find + + def find(if_none_proc = nil) # :nodoc: + Primitive.attr! :inline_block, :c_trace + + unless defined?(yield) + return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, ary_enum_length)' + end + _i = 0 + value = nil + while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) }) + return value if yield(value) + end + if_none_proc&.call + end + end end end diff --git a/hash.c b/hash.c index dbd8f76950fb28..fc8bfa24eb2f36 100644 --- a/hash.c +++ b/hash.c @@ -4850,7 +4850,7 @@ rb_hash_any_p(int argc, VALUE *argv, VALUE hash) * h.dig(:hello) # => nil * h.default_proc = -> (hash, _key) { hash } * h.dig(:hello, :world) - * # => {:foo=>{:bar=>[:a, :b, :c]}} + * # => {foo: {bar: [:a, :b, :c]}} * * Related: {Methods for Fetching}[rdoc-ref:Hash@Methods+for+Fetching]. */ diff --git a/io_buffer.c b/io_buffer.c index f1afc3d3baf48e..4bb4685e744d99 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -1481,7 +1481,7 @@ rb_io_buffer_locked(VALUE self) * * for a buffer created from scratch: free memory. * * for a buffer created from string: undo the association. * - * After the buffer is freed, no further operations can't be performed on it. + * After the buffer is freed, no further operations can be performed on it. * * You can resize a freed buffer to re-allocate it. * @@ -3500,7 +3500,7 @@ memory_not(unsigned char * restrict output, unsigned char * restrict base, size_ * call-seq: * ~source -> io_buffer * - * Generate a new buffer the same size as the source by applying the binary NOT + * Generate a new buffer the same size as the source by applying the unary NOT * operation to the source. * * ~IO::Buffer.for("1234567890") @@ -3690,7 +3690,7 @@ memory_not_inplace(unsigned char * restrict base, size_t size) * call-seq: * source.not! -> io_buffer * - * Modify the source buffer in place by applying the binary NOT + * Modify the source buffer in place by applying the unary NOT * operation to the source. * * source = IO::Buffer.for("1234567890").dup # Make a read/write copy. diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index cd352c22a7abbc..fe05e9d57b2789 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -137,7 +137,7 @@ def copy_to(destination, submodules = false) git "fetch", "--force", "--quiet", *extra_fetch_args(ref), dir: destination end - git "reset", "--hard", @revision, dir: destination + git "reset", "--hard", revision, dir: destination if submodules git_retry "submodule", "update", "--init", "--recursive", dir: destination diff --git a/object.c b/object.c index 07eb1d8e975251..a7b72196d59fb8 100644 --- a/object.c +++ b/object.c @@ -2126,28 +2126,52 @@ static VALUE rb_mod_initialize_exec(VALUE module); /* * call-seq: - * Module.new -> mod - * Module.new {|mod| block } -> mod + * Module.new -> new_module + * Module.new {|module| ... } -> new_module * - * Creates a new anonymous module. If a block is given, it is passed - * the module object, and the block is evaluated in the context of this - * module like #module_eval. + * Returns a new anonymous module. * - * fred = Module.new do - * def meth1 - * "hello" - * end - * def meth2 - * "bye" - * end - * end - * a = "my string" - * a.extend(fred) #=> "my string" - * a.meth1 #=> "hello" - * a.meth2 #=> "bye" + * The module may be assigned to a name, + * which should be a constant name + * in capitalized {camel case}[https://en.wikipedia.org/wiki/Camel_case] + * (e.g., +MyModule+, not +MY_MODULE+). + * + * With no block given, returns the new module. + * + * MyModule = Module.new + * MyModule.class # => Module + * MyModule.name # => "MyModule" + * + * With a block given, calls the block with the new (not yet named) module: + * + * MyModule = Module.new {|m| p [m.class, m.name] } + * # => MyModule + * MyModule.class # => Module + MyModule.name # => "MyModule" + * + * Output (from the block): + * + * [Module, nil] + * + * The block may define methods and constants for the module: + * + * MyModule = Module.new do |m| + * MY_CONSTANT = "#{MyModule} constant value" + * def self.method1 = "#{MyModule} first method (singleton)" + * def method2 = "#{MyModule} Second method (instance)" + * end + * MyModule.method1 # => "MyModule first method (singleton)" + * class Foo + * include MyModule + * def speak + * MY_CONSTANT + * end + * end + * foo = Foo.new + * foo.method2 # => "MyModule Second method (instance)" + * foo.speak + * # => "MyModule constant value" * - * Assign the module to a constant (name starting uppercase) if you - * want to treat it like a regular module. */ static VALUE