Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- class A
- def qwerty; @q; end # manual getter
- def qwerty=(value); @q = value; end # manual setter, but attr_accessor is same
- def asdf; self.qwerty = 4; end # "self." is necessary in ruby?
- def xxx; asdf; end # we can invoke nonsetters w/o "self."
- def dump; puts "qwerty = #{qwerty}"; end
- end
- a = A.new
- a.xxx
- a.dump
- using System;
- public class A {
- public A() {}
- int q;
- public int qwerty {
- get { return q; }
- set { q = value; }
- }
- public void asdf() { qwerty = 4; } // C# setters work w/o "this."
- public void xxx() { asdf(); } // are just like other methods
- public void dump() { Console.WriteLine("qwerty = {0}", qwerty); }
- }
- public class Test {
- public static void Main() {
- A a = new A();
- a.xxx();
- a.dump();
- }
- }
- using System;
- public class A {
- public A() {}
- public int test { get { return 4; }}
- public int useVariable() {
- int test = 5;
- return test;
- }
- public int useMethod() {
- int test = 5;
- return this.test;
- }
- }
- public class Test {
- public static void Main() {
- A a = new A();
- Console.WriteLine("{0}", a.useVariable()); // prints 5
- Console.WriteLine("{0}", a.useMethod()); // prints 4
- }
- }
- qwerty = 4
- class A
- def test
- 4
- end
- def use_variable
- test = 5
- test
- end
- def use_method
- test = 5
- self.test
- end
- end
- a = A.new
- a.use_variable # returns 5
- a.use_method # returns 4
- var = expr // assignment
- method = expr // setter method invocation
- var = expr // assignment (new or existing)
- // method = expr, disallow setter method invocation without .
- symbol = expr // push 'symbol=' onto parse tree and decide later
- // if local variable is def'd somewhere in scope: assignment
- // else if a setter is def'd in scope: invocation
Add Comment
Please, Sign In to add comment