[#79440] [Ruby trunk Bug#13188] Reinitialize Ruby VM. — shyouhei@...
Issue #13188 has been updated by Shyouhei Urabe.
6 messages
2017/02/06
[#79441] Re: [Ruby trunk Bug#13188] Reinitialize Ruby VM.
— SASADA Koichi <ko1@...>
2017/02/06
On 2017/02/06 10:10, shyouhei@ruby-lang.org wrote:
[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>
Hi,
15 messages
2017/02/15
[#79541] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/15
Em 15-02-2017 05:05, Daniel Ferreira escreveu:
[#79543] Re: Immutable Strings vs Symbols
— Daniel Ferreira <subtileos@...>
2017/02/16
Hi Rodrigo,
[#79560] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/16
Em 15-02-2017 22:39, Daniel Ferreira escreveu:
[ruby-core:79697] [Ruby trunk Feature#13026] Public singleton methods
From:
subtileos@...
Date:
2017-02-22 18:53:27 UTC
List:
ruby-core #79697
Issue #13026 has been updated by Daniel Ferreira.
Yukihiro Matsumoto wrote:
> Interesting. Could you tell us expected use-case?
>
> Matz.
Hi Matz. Thank you for your question and the opportunity.
Unit tests are one of the ways I use to enforce the class/module API contract.
So for a given class:
``` ruby
class Foo
class << self
def foo
:foo
end
protected
def bar
:bar
end
private
def baz
:baz
end
end
end
```
I usually have the following unit test:
``` ruby
require "minitest/autorun"
class TestFoo < Minitest::Test
def test_public_singleton_interface
public_singleton_methods = Foo.singleton_methods & Foo.public_methods(false)
assert_equal [:foo], public_singleton_methods
end
end
```
I also tend to inspect my module/class interfaces while in debugging mode.
`Foo.public_singleton_methods` it is much easier to type than the intersection I'm using currently.
I don't believe refinements are an option here.
Monkey patching is something I would like to avoid as much as possible.
This comes inline with my idea of clearly defining contract interfaces.
This is one of the aspects of it. There are many more.
Kind regards,
Daniel
----------------------------------------
Feature #13026: Public singleton methods
https://bugs.ruby-lang.org/issues/13026#change-63118
* Author: Daniel Ferreira
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Abstract
---------
I would like to propose the implementation of:
```
Object#public_singleton_methods
```
`Object#public_singleton_methods` should return a list of public singleton methods.
Background
------------
Currently `Object#singleton_methods` returns a list of public and protected singleton methods.
Currently the best way I know of retrieving a list of public singleton methods is:
```
foo = Foo.new
foo.singleton_methods(false) & foo.public_methods(false)
```
I consider the definition of the public interface of any object very important.
For that reason I tend to keep it as simple as possible.
Also, the way I like to enforce the design is by using unit tests, testing the interface itself.
That way a change of the interface is very visible for the developer and code reviewer.
I also tend to use `protected` a lot to give private methods a higher level of relevance.
Implementation
---------------
This is a feature that I would be very interested in developing.
It would be my first contribution to ruby core.
If you understand that it is worth the effort I would be more than happy to do it.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>