aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_delegate.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add instance_methods to class generated by DelegateClassMasataka Pocke Kuwabara2020-07-091-0/+34
| | | | | Also, make DelegateClass.instance_method fallback to superclass. Fixes [Bug #16982]
* Fix SimpleDelegator respond_to? regressionJean Boussier2020-02-031-0/+14
| | | | | | | | | In 2.6, SimpleDelegator would always use the target `respond_to?` In 2.7.0 it doesn't if the target does not inherit from Object. This breaks compatibility for delegated objects that inherit from BasicObject and redefine `respond_to?`.
* delegate.rb: fixed keyword arguments in DelegateClassNobuyoshi Nakada2020-01-301-0/+8
| | | | | `Delegator.delegating_block` should delegate keyword arguments separately. [ruby-core:96949]
* Call initialize_clone with freeze: false if clone called with freeze: falseJeremy Evans2020-01-031-0/+15
| | | | | | | | | | | | | | | | | | | This makes it possible to initialize_clone to correctly not freeze internal state if the freeze: false keyword is passed to clone. If clone is called with freeze: true or no keyword, do not pass a second argument to initialize_clone to keep backwards compatibility. This makes it so that external libraries that override initialize_clone but do not support the freeze keyword will fail with ArgumentError if passing freeze: false to clone. I think that is better than the current behavior, which succeeds but results in an unfrozen object with frozen internals. Fix related issues in set and delegate in stdlib. Fixes [Bug #14266]
* Update tests for full keyword argument separationJeremy Evans2020-01-021-3/+1
|
* Reword keyword arguments warning messages to convey these are deprecation ↵Marc-Andre Lafortune2019-12-231-1/+1
| | | | warnings
* vm_args.c: rephrase the warning message of keyword argument separationYusuke Endoh2019-12-201-1/+1
| | | | | | | | | | (old) test.rb:4: warning: The last argument is used as the keyword parameter test.rb:1: warning: for `foo' defined here; maybe ** should be added to the call? (new) test.rb:4: warning: The last argument is used as keyword parameters; maybe ** should be added to the call test.rb:1: warning: The called method `foo' is defined here
* Support delegates for BasicObjectJeremy Evans2019-10-101-0/+8
| | | | | | | | | 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]
* Add Module#ruby2_keywords for passing keywords through regular argument splatsJeremy Evans2019-09-251-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix visibility of some methods when using DelegateClassJeremy Evans2019-05-301-0/+31
| | | | | | | | | | | | | | | | 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]
* Allow DelegateClass() to module_eval given blockJeremy Evans2019-05-301-0/+7
| | | | | | | | | | 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]
* delegate.rb: don't look for methods on KernelÉtienne Barrié2019-05-131-0/+7
| | | | | | | | | 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
* Add FrozenError as a subclass of RuntimeErrorshyouhei2017-12-121-2/+2
| | | | | | | | | | | | | | FrozenError will be used instead of RuntimeError for exceptions raised when there is an attempt to modify a frozen object. The reason for this change is to differentiate exceptions related to frozen objects from generic exceptions such as those generated by Kernel#raise without an exception class. 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@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Delegate to `eql?` [Fix GH-1564]nobu2017-06-241-0/+20
| | | | | | | | * 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
* lib/delegate.rb: Specify frozen_string_literal: true.kazu2017-01-061-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add frozen_string_literal: false for all filesnaruse2015-12-161-0/+1
| | | | | | 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
* delegate.rb: keep special methodsnobu2014-01-171-0/+57
| | | | | | | * 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
* delegate.rb: ignore unset targetnobu2013-12-041-0/+12
| | | | | | | | | | | * 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
* delegate.rb: check if target is setnobu2013-11-211-0/+14
| | | | | | | | * 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
* delegate.rb: refix r43682nobu2013-11-191-0/+9
| | | | | | | * 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
* delegate.rb: get rid of global function interferencenobu2013-11-151-0/+12
| | | | | | | * 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
* * lib/delegate.rb (Delegator#methods): Kernel#methods receivesnaruse2011-12-041-0/+7
| | | | | | 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
* * object.c (rb_obj_clone): call initialize_clone hook method tomatz2010-02-081-0/+3
| | | | | | | | | | | | | | | | 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
* * test/test_delegate.rb (TestDelegateClass::IV#initialize): shouldnobu2010-02-061-0/+2
| | | | | | | | | | set delegation target. * test/test_delegate.rb (TestDelegateClass#test_copy_frozen): clone of frozen delegator also should be frozen. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/delegate.rb (Delegator): include copy of Kernel.nobu2010-02-051-6/+42
| | | | | | | | | | [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
* * lib/delegate.rb (Delegator): now inherits BasicObject.nobu2010-02-031-0/+18
| | | | | | | [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
* * marshal.c (w_object): reverted r26007. [ruby-dev:39845]nobu2009-12-071-0/+16
| | | | | | | * test/test_delegate.rb (test_marshal): moved from test_marshal.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/delegate.rb (Delegator::public_api): take snapshot ofmatz2009-10-061-0/+22
| | | | | | | | | | | | public method at the beginning time. * lib/delegate.rb (SimpleDelegator#initialize): use Delegator.public_api since public_method might be added after initialization. [ruby-dev:39383] * lib/delegate.rb (DelegateClass): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add test for {SimpleDelegator, DelegateClass}#class .xibbar2008-10-181-0/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add a test for [ruby-dev:34808].akr2008-05-241-0/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/test_delegate.rb: add new test file for delegate.rb.usa2008-01-161-0/+15
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e