#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep 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. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    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]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0
    It doesn't work in the first place !
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2007
    Location
    India
    Posts
    3
    Rep 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
    Originally Posted by shehio
    It doesn't work in the first place !
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2007
    Location
    India
    Posts
    3
    Rep Power
    0
    What do you want to achieve from your program?

    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

IMN logo majestic logo threadwatch logo seochat tools logo