[swift-evolution] Python Interop with Swift 4+
David Waite
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:
>
<snip>
> Moreover, Ruby allows classes to have instance variables with the same name as methods:
>
> class Foo
> def initialize()
> @bar = 5
> end
>
> def bar()
> puts “Hello"
> end
> end
>
> 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)
-DW
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171120/dbe934a1/attachment.html>
More information about the swift-evolution
mailing list