summaryrefslogtreecommitdiff
path: root/lib/delegate.rb
AgeCommit message (Collapse)Author
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-10-10Support delegates for BasicObjectJeremy Evans
For BasicObject, bind the Kernel respond_to? instance method to the object and call it instead of calling the method directly. Also, use bind_call(recv, ...) for better performance. Fixes [Bug #16127] Notes: Merged: https://github.com/ruby/ruby/pull/2546
2019-09-25Add Module#ruby2_keywords for passing keywords through regular argument splatsJeremy Evans
This approach uses a flag bit on the final hash object in the regular splat, as opposed to a previous approach that used a VM frame flag. The hash flag approach is less invasive, and handles some cases that the VM frame flag approach does not, such as saving the argument splat array and splatting it later: ruby2_keywords def foo(*args) @args = args bar end def bar baz(*@args) end def baz(*args, **kw) [args, kw] end foo(a:1) #=> [[], {a: 1}] foo({a: 1}, **{}) #=> [[{a: 1}], {}] foo({a: 1}) #=> 2.7: [[], {a: 1}] # and warning foo({a: 1}) #=> 3.0: [[{a: 1}], {}] It doesn't handle some cases that the VM frame flag handles, such as when the final hash object is replaced using Hash#merge, but those cases are probably less common and are unlikely to properly support keyword argument separation. Use ruby2_keywords to handle argument delegation in the delegate library. Notes: Merged: https://github.com/ruby/ruby/pull/2477
2019-06-02delegate.rb: markup method namesNobuyoshi Nakada
2019-05-30Fix visibility of some methods when using DelegateClassJeremy Evans
Public instance methods added to a delegated class after the creation of the delegate class were not returned by the public_instance_methods class method of the delegate class. Protected instance methods in the delegated class when the delegate class is created were returned by the public_methods instance method of the delegate class. Patch mostly from Kenichi Kamiya <kachick1@gmail.com> in GitHub pull request 926. Minor changes to get it to apply, and to fix tests after applying by me. Fixes [Bug #11512]
2019-05-30Allow DelegateClass() to module_eval given blockJeremy Evans
Methods that return classes often module_eval the given block (e.g. Class.new and Struct.new). This allows DelegateClass to work similarly. This makes it easier to use DelegateClass directly without subclassing, so as not to create an unnecessary subclass. Implements [Feature #15842]
2019-05-13delegate.rb: don't look for methods on KernelÉtienne Barrié
Instead, look for instance methods of Kernel. Otherwise, instance methods of Module (which are methods of Kernel itself) are mistakenly believed to exist, and it fails when calling Kernel.instance_method(). Closes: https://github.com/ruby/ruby/pull/1422
2019-05-10Fix missing `\A`Kazuhiro NISHIYAMA
2017-12-12Add uplevel keyword to Kernel#warn and use itshyouhei
If uplevel keyword is given, the warning message is prepended with caller file and line information and the string "warning: ". The use of the uplevel keyword makes Kernel#warn format output similar to how rb_warn formats output. This patch modifies net/ftp and net/imap to use Kernel#warn instead of $stderr.puts or $stderr.printf, since they are used for printing warnings. This makes lib/cgi/core and tempfile use $stderr.puts instead of warn for debug logging, since they are used for debug printing and not for warning. This does not modify bundler, rubygems, or rdoc, as those are maintained outside of ruby and probably wish to remain backwards compatible with older ruby versions. rb_warn_m code is originally from nobu, but I've changed it so that it only includes the path and lineno from uplevel (not the method), and also prepends the string "warning: ", to make it more similar to rb_warn. From: Jeremy Evans code@jeremyevans.net Signed-off-by: Urabe Shyouhei shyouhei@ruby-lang.org git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Use caller with length to reduce unused stringskazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-24Delegate to `eql?` [Fix GH-1564]nobu
* lib/delegate.rb (eql?): Delegate to `eql?` of the inner object. based on the patch by giginet <giginet.net@gmail.com>. [ruby-core:76950] [Bug #12684] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-06lib/delegate.rb: Specify frozen_string_literal: true.kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-05* lib/delegate.rb: Added missing spaces and Removed needless spaces.hsbt
[fix GH-1454][ci skip] Patch by @bogdanvlviv git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16Add frozen_string_literal: false for all filesnaruse
When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-09* lib/delegate.rb: Remove backtrace cleaning for delegated methodszzak
This patch was provided by Rafael França and greatly improves performance when an exception is raised. [Bug #11461] Before: Calculating ------------------------------------- default 86.209k i/100ms default raising 2.209k i/100ms ------------------------------------------------- default 1.953M (±11.0%) i/s - 9.655M default raising 21.826k (±13.5%) i/s - 108.241k After: Calculating ------------------------------------- default 72.211k i/100ms default raising 34.288k i/100ms ------------------------------------------------- default 2.013M (±18.7%) i/s - 9.460M default raising 623.950k (± 9.7%) i/s - 3.120M Benchmark: require 'delegate' require 'benchmark/ips' class Foo def name 'foo' end def bla raise end end class Bar < DelegateClass(Foo) end bar = Bar.new(Foo.new) Benchmark.ips do |b| b.report('default') { bar.name } b.report('default raising') { bar.bla rescue nil } end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-13* lib/delegate.rb: [DOC] Update SimpleDelegator example. [ci skip]eregon
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-23* lib/delegate.rb: fix a typo.hsbt
[fix GH-881][ci skip] Patch by @Zorbash git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-26* lib/delegate.rb: split executable code into sample directory.hsbt
* sample/delegate.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-30* lib/delegate.rb: [DOC] Document raise in Delegator classzzak
Patch by @lucasmazza. [Fixes GH-621] https://github.com/ruby/ruby/pull/621 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-08* lib/delegate.rb: Fix example of using delegator.ayumin
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-17delegate.rb: keep special methodsnobu
* lib/delegate.rb (Delegator): keep source information methods which start and end with '__'. [ruby-core:58572] [Bug #9155] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-04delegate.rb: ignore unset targetnobu
* lib/delegate.rb (Delegator#method_missing): ignore the target if not set, and delegate to global methods. [ruby-core:58572] [Bug #9155] * lib/delegate.rb (Delegator#respond_to_missing): ditto. * lib/delegate.rb (SimpleDelegator#__getobj__): yield and return if not delegated but a block is given, like as Hash#fetch. * lib/delegate.rb (DelegateClass#__getobj__): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21delegate.rb: check if target is setnobu
* lib/delegate.rb (SimpleDelegator#__getobj__): target object must be set. * lib/delegate.rb (DelegateClass#__getobj__): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21delegate.rb: try private methods after the targetnobu
* lib/delegate.rb (Delegator#method_missing): try private methods defined in Kernel after the target. [Fixes GH-449] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-19delegate.rb: refix r43682nobu
* lib/delegate.rb (Delegator#send): separate from method_missing so that super calls proper method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15delegate.rb: get rid of global function interferencenobu
* lib/delegate.rb (Delegator#send): override to get rid of global function interference. [Fixes GH-449] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10* lib/delegate.rb: Add example for __setobj__ and __getobj__zzak
[Bug #8615] Patch by Caleb Thompson git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-08* lib/delegate.rb: Added documentation for Delegator#!. Patch bydrbrain
Zachary Scott. [ruby-trunk - Feature #6534] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-04* lib/delegate.rb (Delegator#methods): Kernel#methods receivesnaruse
zero or one argument. [ruby-core:37118] [Bug #4882] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-27 * lib/delegate.rb: Move file-level documentation to the appropriatedrbrain
classes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-19* lib: revert r31635-r31638 and untabify with expand(1).nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-18 * lib: Convert tabs to spaces for ruby files perdrbrain
http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto#coding-style Patch by Steve Klabnik [Ruby 1.9 - Bug #4730] Patch by Jason Dew [Ruby 1.9 - Feature #4718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-22* lib/delegate.rb: Forward #trust, #untrust, #taint and #untaintmarcandre
to both the delegator and __getobj__ [ruby-core:26138] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-12* lib/delegate.rb: Delegate !=, eql? and hash [ruby-core:26139]marcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-30* lib/delegate: Delegator: combine (public|protected) methods withmarcandre
those of the delegated object. [ruby-core:27224] DelegateClass: combine (public|protected) instance methods with those of the delegated superclass. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-10Fix :nodoc: definition. [ruby-dev:40949]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-08* object.c (rb_obj_clone): call initialize_clone hook method tomatz
call initialize_copy. * object.c (rb_obj_dup): call initialize_dup hook. * lib/delegate.rb (Delegator#initialize_clone): use new hook to implement deep copy. [ruby-dev:40242] * lib/delegate.rb (Delegator#initialize_dup): ditto. * test/test_delegate.rb (TestDelegateClass#test_copy_frozen): add a test to ensure #clone copies frozen status. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-06* lib/delegate.rb (Delegator#method_missing),nobu
(Delegator.delegating_block): don't hide backtrace from __getobj__ and reduced exception messages when $DEBUG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-05* lib/delegate.rb (Delegator): include copy of Kernel.nobu
[ruby-dev:40314] * lib/delegate.rb (Delegator#{dup,clone}): class of copy should be Delegator. [ruby-dev:40313] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-03* lib/delegate.rb (Delegator): now inherits BasicObject.nobu
[ruby-dev:39154], [Bug #2679], [ruby-dev:40242] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-02* lib/delegate.rb (Delegator#marshal_dump): excludenobu
delegator-specific instance variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-01-28* lib/delegate.rb (Delegator#initialize_copy): use initialize_copymatz
instead of overriding clone/dup. [ruby-dev:40221] it now always clones the target, it might cause incompatibility. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-29* lib/delegate.rb (marshal_dump/load): Provide forward compatibility ↵marcandre
[ruby-core:24211] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-24* lib/delegate.rb (marshal_dump/load): dump & load instance variables by ↵marcandre
default [ruby-core:24211] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-24* object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063]matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-17* vm_method.c (basic_obj_respond_to): call #respond_to_missing?matz
always with two arguments. [ruby-core:26090] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-17* lib/delegate.rb (Delegator#respond_to_missing): warn only whenmatz
specified method is a private. [ruby-dev:39498] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-16* lib/delegate: rdoc typomarcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-16* lib/delegate.rb (Delegator#method_missing): remove backtracematz
lines _until_ `method_missing'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-16* lib/delegate.rb (Delegator#freeze): #freeze should freeze selfmatz
and the target at once. [ruby-core:26118] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e