ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94372] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
@ 2019-08-15 20:21 ` sbellware
  2019-08-15 20:39 ` [ruby-core:94373] " XrXr
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: sbellware @ 2019-08-15 20:21 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been reported by sbellware (Scott Bellware).

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106

* Author: sbellware (Scott Bellware)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94373] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
  2019-08-15 20:21 ` [ruby-core:94372] [Ruby master Bug#16106] UnboundMethod owner points to base class sbellware
@ 2019-08-15 20:39 ` XrXr
  2019-08-15 23:10 ` [ruby-core:94375] " shevegen
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: XrXr @ 2019-08-15 20:39 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been updated by alanwu (Alan Wu).


Yes, this is behavior is expected. Changing it would not be backwards compatible.

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106#change-80786

* Author: sbellware (Scott Bellware)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94375] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
  2019-08-15 20:21 ` [ruby-core:94372] [Ruby master Bug#16106] UnboundMethod owner points to base class sbellware
  2019-08-15 20:39 ` [ruby-core:94373] " XrXr
@ 2019-08-15 23:10 ` shevegen
  2019-08-16  0:57 ` [ruby-core:94377] " sbellware
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: shevegen @ 2019-08-15 23:10 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been updated by shevegen (Robert A. Heiler).


I guess the documentation could mention that behaviour so that other
rubyists won't be confused, as alanwu pointed out e. g:

https://ruby-doc.org/core/UnboundMethod.html#method-i-owner

(Or the other documentation site; I just happen to find the above
more readily via a quick google search.)

On a side note, perhaps the name is not ideal, since I can see why
sbellware may be surprised - UnboundMethod implies to me a method
not attached to anywhere, so I was a bit surprised to see that it
still has a pointer to the original class from where it was created
from. Although I understand that this may be useful; it just seems
a bit peculiar to me ... perhaps it is a MostlyUnboundMethod. :P

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106#change-80790

* Author: sbellware (Scott Bellware)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94377] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-15 23:10 ` [ruby-core:94375] " shevegen
@ 2019-08-16  0:57 ` sbellware
  2019-09-09 23:55 ` [ruby-core:94880] " merch-redmine
  2019-09-21 21:19 ` [ruby-core:95025] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: sbellware @ 2019-08-16  0:57 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been updated by sbellware (Scott Bellware).


Indeed, that's why I was surprised. I wasn't expecting `owner` to be a pointer to a class that I wasn't working with.

To correct the code I was working on, I now pass around both the UnboundMethod instance as well as the class, and ignore the `owner` method entirely.

I guess what also throws me, from a usability perspective, is that `owner` seems asymmetrical with Method#receiver, where Method#receiver is a pointer to the de facto instance that the method is from. I appreciate that this is largely immaterial due to the difference between objects and classes, but just a bit of background on what was informing my biases at the time.

Ideally, it might have been nice to have a method named `implementer` on UnboundMethod that does what `owner` does, and have `owner` reflect some symmetry with Method#receiver. Just a thought.

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106#change-80792

* Author: sbellware (Scott Bellware)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:94880] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-16  0:57 ` [ruby-core:94377] " sbellware
@ 2019-09-09 23:55 ` merch-redmine
  2019-09-21 21:19 ` [ruby-core:95025] " eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2019-09-09 23:55 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

The documentation for `owner` states: `Returns the class or module that defines the method.`.  The example given in the documentation shows `method` being called on a Range instance, but having an owner of Enumerable.  So I don't think documentation updates are necessary, and this can be closed.

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106#change-81496

* Author: sbellware (Scott Bellware)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:95025] [Ruby master Bug#16106] UnboundMethod owner points to base class
       [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-09-09 23:55 ` [ruby-core:94880] " merch-redmine
@ 2019-09-21 21:19 ` eregontp
  5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-09-21 21:19 UTC (permalink / raw)
  To: ruby-core

Issue #16106 has been updated by Eregon (Benoit Daloze).


An interesting bit here is that there is no way to get back the module from which the method was retrieved, even though it's shown in #inspect:
```
> Range.instance_method :map
=> #<UnboundMethod: Range(Enumerable)#map>
```

Maybe we should expose `UnboundMethod#origin`? That would be a separate feature request, though.

----------------------------------------
Bug #16106: UnboundMethod owner points to base class
https://bugs.ruby-lang.org/issues/16106#change-81653

* Author: sbellware (Scott Bellware)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
This may not be a bug. It may be my misinterpretation of the feature.

When using UnboundMethod#owner on a class that was created with `Class.new(SomeBaseClass)`, the owner is reported as the `SomeBaseClass `rather than the new class.

This was a surprising outcome, since I presumed that the owner method would point to the class rather than the class's base class.

Example:

```
class SomeClass
  def some_method
  end
end

C = Class.new(SomeClass)

m = C.instance_method(:some_method)

pp m.owner
# => SomeClass

# I would have expected the owner to be C
```

Is this expected behavior?

Thanks,
Scott

---Files--------------------------------
unbound_method_owner_sketch.rb (176 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-09-21 21:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16106.20190815202151@ruby-lang.org>
2019-08-15 20:21 ` [ruby-core:94372] [Ruby master Bug#16106] UnboundMethod owner points to base class sbellware
2019-08-15 20:39 ` [ruby-core:94373] " XrXr
2019-08-15 23:10 ` [ruby-core:94375] " shevegen
2019-08-16  0:57 ` [ruby-core:94377] " sbellware
2019-09-09 23:55 ` [ruby-core:94880] " merch-redmine
2019-09-21 21:19 ` [ruby-core:95025] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).