> On Nov 20, 2017, at 1:16 AM, David Hart via swift-evolution 
> <[email protected]> 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
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to