Martin Tithonium (tithonium) wrote,
Martin Tithonium
tithonium

ruby question

anybody familiar with ruby? google searching hasn't turned up an answer to this.

I want a ruby equivalent to this perl:

foreach my $key (keys %hash) {
$self->{$key} = $hash{$key};
}


which I suspect should take a form like:

hash.each { |key,value| <something involving @ and key> = value }

@#{key} doesn't seem to be valid, so what's the appropriate way to name an instance variable using another variable?

edit: Apaprently, it would be send("#{key}=", value). How.. ugly.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 3 comments