From: "JesĂşs Gabriel y Galán" Date: 2009-11-06T01:21:56+09:00 Subject: Re: question about variables in ruby On Thu, Nov 5, 2009 at 1:18 PM, Mahadev Ittina wrote: > hello folks i am preparing a ruby plugin for sketchup, i hope you can > help me with this really nasty problem i am having > > here is the method ,which belongs to a class > >  def moment_calc > >    weight = 0 >    variable_load = 0 >    permanent_load = 0 >    moment = 0 > >    weight =((25.0*@b*@h) / 10**6) >    prompts = ["Variable Load(kN/m) ", "Permanent Load(kN/m) ", "Max > Moment known(Nmm)"] >    loads = [0.0, 0.0, 0.0] >    results = inputbox prompts, loads, "Other Loads" >    variable_load, permanent_load, moment = results > >    if (moment != 0) >      @M = moment >    else >      uls = (1.35*variable_load + 1.5*permanent_load + > 1.5*weight)*@length >      @M = 0.11*uls*@length >      @shear = 0.60 * uls >    end >  end > > my @b = 280 and @h=300 from before.. when i try to multiply the weight > it should come 2.1 but in this case it is 0.0032 or so.. which is > wrong.. hence because of that my uls values are wrong and hence the > entire following program.. i am pretty sure its problem with the > variables.. just cant figure out where! irb(main):001:0> @b = 280 => 280 irb(main):002:0> @h = 300 => 300 irb(main):003:0> weight =((25.0*@b*@h) / 10**6) => 2.1 This calculation is correct: 2.1, so if you are getting a different result it has to be that @b or @h don't contain what you think they do. Can you try to print @b, @h and weight, and show us the calling code that produces weight being 0.00032? def moment_calc puts "@b is #{@b}" puts "@h is #{@h}" weight =((25.0*@b*@h) / 10**6) puts "weight is #{weight}" end If you put this in your program, what happens? Also, you don't need this: > weight = 0 > variable_load = 0 > permanent_load = 0 > moment = 0 in Ruby you don't need to declare your variables before assigning (another value) to them. So assigning them a 0 only to assign them another value afterwards is not needed. Jesus.