Symbol? Even better.

Mixing some ideas from the Josh code we have...

Remember... as Josh said you shouldn't rely on Hash items order. (this
code does this :/ )
Hashes are not ordered by nature.

http://www.pastie.org/1400695

On Thu, Dec 23, 2010 at 11:10 AM, RichardOnRails
<RichardDummyMailbox58407 / uscomputergurus.com> wrote:
> On Dec 22, 11:55 ¨Βν¬ Κοσθ ΓθεεΌκοσθ®γθ®®®ΐηναιμ®γονΎ χςοτεΊ
>> [Note:  ¨Βαςτσ οζ τθισ νεσσαηχεςε ςενοφετο ναλε ιτ μεηαποστ®έ
>>
>> On Wed, Dec 22, 2010 at 10:10 PM, RichardOnRails <
>>
>>
>>
>> RichardDummyMailbox58... / uscomputergurus.com> wrote:
>> > I pasted code to prompt for a couple of parameter-values at
>> >http://www.pastie.org/1399710.
>>
>> > Running this code under SciTE produces, for example:
>> > Getting parms
>> >  ¨Βγγουξτ Ξυνβες±²>> >  ¨Βεπος ¨ΒεςιοδΊ ΄µ>> > Showing parms
>> >  ¨Βαγγτίξυν ±²>> >  ¨Βαγγτίπεςιο΄µ>>
>> > It is excessively verbose because I couldn't figure out how to use
>> > meta-language to specify the parameter target names.  ¨Βθαμενε το
>> > using case statements to accept input values and then populate the
>> > instance variables.
>>
>> > Can anyone suggest how I can use the instance variables as targets in
>> > lieu of the case statements?  ¨ΒΤΧχαξτ το ηετθισ χοςλιξχιτθ
>> > meta-programming.  ¨Β δοξ§χαξτ το υσσονε οτθεαππςοαγθσυγθ ασ >> > plug-in for getting arguments.
>>
>> > Thanks in Advance,
>> > Richard
>>
>> I think you are looking for instance_variable_set and instance_variable_get.
>> I don't really understand all the decisions you made, such as the array of
>> hashes, to me that implies you want ordered hashes, but are on 1.8 (If you
>> are in Rails, you have ActiveSupport loaded, and it provides an OrderedHash
>> class that you can use) since they are ordered in 1.9. To get around that, I
>> just made it an Array of Structs. Anyway, hopefully you can get out of this
>> whatever you're trying to do.
>>
>> class X
>>
>> def initialize
>> param = Struct.new :human_readable , :ivar
>> @rpt_parms = [
>> param.new( "Account Number" , "@acct_num" ,
>> param.new( "Report  ¨ΒεςιοδΆ ΆΐαγγτίπεςιοδΆ ©¬
>> ]
>> end
>>
>> def get_parms
>> @rpt_parms.each do |param|
>> print "\t#{param.human_readable}: "
>> instance_variable_set( param.ivar , gets.to_i ) # don't needo chomp,
>> to_i will ignore the newline
>> end
>> end
>>
>> def show_parms
>> @rpt_parms.each do |param|
>> value = instance_variable_get(param.ivar)
>> puts "\t#{param.human_readable} = #{value}"
>> end
>> end
>>
>> def run
>> puts "Getting parms"
>> get_parms
>> puts "Showing parms"
>> show_parms
>> end
>>
>> end
>>
>> X.new.run
>
>> I think you are looking for instance_variable_set and instance_variable_get.
> That's also exactly the thing I needed!  ¨Βψγεμμεξτ΅΅
>
>> To get around that, I just made it an Array of Structs.
> Another responder did what I really wanted but was too stupid to do
> is:
>  ¨ΒπαςνΑγγουξΞανε½Ύ Ίαγγτίξανε> Account Number" => :acct_num
> } # etc.
>
> Thanks very much for your insights.
> Best wishes,
> Richard
>
>