[swift-evolution] Python Interop with Swift 4+
david at alkaline-solutions.com
Mon Nov 20 02:32:17 CST 2017
> On Nov 20, 2017, at 1:16 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> Moreover, Ruby allows classes to have instance variables with the same name as methods:
> class Foo
> def initialize()
> @bar = 5
> def bar()
> puts “Hello"
> In that case, how would one implement DynamicMemberLookupProtocol for the lookup of bar, and what would the return value be? Its entirely context sensitive.
I do not believe Ruby does not give you direct external access to variables. Everything with a ‘.’ is a function call.
You would use e.g.
Foo.new.instance_variable_get("@bar”) // => 5
attr :bar exposes a variable @bar through functions bar() and bar=() (and also optimizes storage in some implementations)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution