[Ironruby-core] Why does attr_accessor create a property, but method is just a method?

Jörg W Mittag JoergWMittag+Ruby at GoogleMail.Com
Fri Jul 23 11:16:58 EDT 2010


Brian Genisio wrote:
> Thinking on this further, if there were some sort of interop-specific class
> method... like attr_clr_property :foo, that caused any methods named foo and
> foo=(var) to be visible to .Net as properties, that would be sufficient.
> 
> Any thoughts on this?

Alternative suggestion: make method redefinition work in this case,
like this:

    var engine = IronRuby.Ruby.CreateEngine();
    var script = @"
        class Test
          attr_accessor :a, :m

          def m; @m end
          def m=(val) @m = val end

          def initialize; @a, @m = 'automatic', 'manual' end
        end

        Test.new
    ";
    var testObject = engine.Execute(script);

    var automatic = testObject.a;
    var manual = testObject.m;

    Console.WriteLine(automatic);
    Console.WriteLine(manual);    // should print "manual"
    Console.ReadLine();

jwm



More information about the Ironruby-core mailing list