Forum: IronRuby overriding indexers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2009-05-28 20:26
(Received via mailing list)
Hi
How do I override an indexer on a C# class?

public class IndexerContained{

        private Dictionary<string, string> _inner = new
Dictionary<string,
string>{
            { "key1", "value1" },
            { "key2", "value2" },
            { "key3", "value3" },
            { "key4", "value4" }
        };

        public virtual string this[string name]{
          get { return _inner[name]; }
          set { _inner[name] = value; }
        }
    }

I would like to override that indexer with something like

class IndexerContainedMock

  def [](*args)
    5
  end

  def []=(*args)
    # nothing here
  end
end

Am I doing it wrong or is that not implemented yet?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
E1deaac6561498a0e7472e6268ea9ccc?d=identicon&s=25 Jimmy Schementi (Guest)
on 2009-05-28 21:19
(Received via mailing list)
Pretty sure this isn’t implemented yet, as you can accomplish the same
type of effect with method_missing:

_inner.key2 = “value2”

It definitely should be fixed, but not sure if anyone has it in their
sights. So open a bug =)

From: ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] On Behalf Of Ivan Porto
Carrero
Sent: Thursday, May 28, 2009 10:49 AM
To: ironruby-core
Subject: [Ironruby-core] overriding indexers

Hi

How do I override an indexer on a C# class?

public class IndexerContained{

        private Dictionary<string, string> _inner = new
Dictionary<string, string>{
            { "key1", "value1" },
            { "key2", "value2" },
            { "key3", "value3" },
            { "key4", "value4" }
        };

        public virtual string this[string name]{
          get { return _inner[name]; }
          set { _inner[name] = value; }
        }
    }

I would like to override that indexer with something like

class IndexerContainedMock

  def [](*args)
    5
  end

  def []=(*args)
    # nothing here
  end
end

Am I doing it wrong or is that not implemented yet?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
1e39a948a58f4569c53d971c2e120920?d=identicon&s=25 Ivan Porto carrero (casualjim)
on 2009-05-28 21:21
(Received via mailing list)
hehe it's for mocking .. more specifically HttpSessionStateBase ;)
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)



On Thu, May 28, 2009 at 9:11 PM, Jimmy Schementi <
This topic is locked and can not be replied to.