callstack - Ruby: method lookup in an outer frame -


I am trying to clone that F # people call "forward pipe" operator with Ruby and some Partial breakthrough was achieved.

Class Object Dft> & Gt; (Rhs) rhs.ispect if rhs.is_a puts it? The symbol is called the method (RAS). Insipent method (RAS). Call self-form rhs.call self-end and end # 1 in 1024; Gt; & Gt; 3 Example 2 puts (1..10) .select {| X | X.even? } {.map | X | 10 × x}. Example # Example 3 (1..10) .select {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; Proc.new {| X | Puts x} # example 4 (1..10) .select {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; Lambda {| X | Puts x} # Examples 5 (1..10) .select {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; - & gt; (X) {puts x} # example6 (1..10) .select {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; Method (: puts) #Example7 (1..10) .select {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; : Puts #Example 8 square Foo def initialize (x) @x = x end def bar (v) "# {@ x}: # {v}" end puts def (1..10). Selection {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; Method (: Bar) End DEF Quicks (1..10). Selection {| X | X.even? } {.map | X | 10 × x} Interviews & gt; & Gt; : End of the End Foo.new (10) .baz # Example 9 Foo.new (20) .quux

I am stuck in the previous example (9). The result is

  == Example 1 == 128 == Example 2 == [20, 40, 60, 80, 100] == Example 3 == # & lt; Proc: 0x000000022652d0 @ / Fsharp-forward-pipe.rb: 28 & gt; [20, 40, 60, 80, 100] == Example 4 == # & lt; Proc: 0x00000002265050 @. / Fsharp-forward-pipe.rb: 31 (lambda) & gt; [20, 40, 60, 80, 100] == Example 5 == # & lt; Proc: 0x00000002264dd0 @ / Fsharp-forward-pipe.rb: 34 (lambda) & gt; [20, 40, 60, 80, 100] == Example 6 == # & lt; Method: Object (Kernel) # puts & gt; [20, 40, 60, 80, 100] == Example 7 ==: puts # & lt; Method: String (Kernel) # puts & gt; [20, 40, 60, 80, 100] == Example 8 == # & lt; Method: Foo # Bar & gt; 10: [20, 40, 60, 80, 100] == Example 9 ==: bar ./fsharp-forward-pipe.rb:12:in `method ': Undefined method' bar 'for' class' (name Error) ./fsharp-forward-pipe.rb:12:in` & gt; & Gt; 'From ./fsharp-forward-pipe.rb:57:in' quux 'to ./fsharp-forward-pipe.rb:63:in `& lt; Main & gt; ' 

That is, if I change method (: quux) for the beauty of notation: : quux and And gt; & Gt; The operators resolve this in some method, instead of the caller frame object # & gt; & Gt; Actually even the 7th example faced the same problem, but : puts to string # puts / <> Code was solved, which agreed with my desired method, Kernel # puts it .

Is it possible to specify the frame in which any symbol is solved in a method?


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -