Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 24th, 2011, 09:35 AM
 shehio
Registered User

Join Date: Aug 2011
Posts: 2
Time spent in forums: 16 m 5 sec
Reputation Power: 0
Problem new to ruby?

# polynomial program :
class Term
attr_accessor: coeff, :sign
@@symbol
def initialization(Coeff)
@coeff = coeff
@sign = determine_sign(coeff)
end
private
def determine_sign(coeff)
mod = coeff.abs
if(coeff/mod)
return '+'
else
return '-'
end
# why it doesn't work??
end
class Poly
def initialization
@array = []
end

end

#2
August 24th, 2011, 02:10 PM
 MrFujin
Lord of the Dance

Join Date: Oct 2003
Posts: 3,350
Time spent in forums: 2 Months 2 Weeks 4 Days 19 h 5 m 54 sec
Reputation Power: 1828
Please tell us what is wrong. What did you expect? what happened?

You can use code tags to keep the code formatting/indentation:
[code] insert code here [/code]

#3
August 25th, 2011, 08:38 AM
 shehio
Registered User

Join Date: Aug 2011
Posts: 2
Time spent in forums: 16 m 5 sec
Reputation Power: 0
It doesn't work in the first place !

#4
September 6th, 2011, 12:08 AM
 IndianGuru
Registered User

Join Date: May 2007
Location: India
Posts: 3
Time spent in forums: 33 m 47 sec
Reputation Power: 0
After removing the syntax errors, here's your code:
Code:
```class Term
attr_accessor :coeff, :sign
@@symbol

def initialization(coeff)
@coeff = coeff
@sign = determine_sign(coeff)
end

private
def determine_sign(coeff)
mod = coeff.abs
if(coeff/mod)
return '+'
else
return '-'
end
end
end

class Poly
def initialization
@array = []
end
end```

Quote:
 Originally Posted by shehio It doesn't work in the first place !

#5
September 7th, 2011, 12:04 AM
 IndianGuru
Registered User

Join Date: May 2007
Location: India
Posts: 3
Time spent in forums: 33 m 47 sec
Reputation Power: 0
What do you want to achieve from your program?

Quote:
 Originally Posted by IndianGuru After removing the syntax errors, here's your code: Code: ```class Term attr_accessor :coeff, :sign @@symbol def initialization(coeff) @coeff = coeff @sign = determine_sign(coeff) end private def determine_sign(coeff) mod = coeff.abs if(coeff/mod) return '+' else return '-' end end end class Poly def initialization @array = [] end end```

 Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Problem new to ruby?