Created
December 17, 2015 13:49
-
-
Save ufeanei/336309e86e9ef1ff7439 to your computer and use it in GitHub Desktop.
Revisions
-
ufeanei created this gist
Dec 17, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ class Octal attr_accessor :octnum def initialize(num) @octnum = num end def not_valid? octnum == '0' || octnum =~ /[A-Fa-f8-9]/ end def to_decimal sum = 0 return sum if not_valid? oct_reverse = octnum.reverse for i in 0...oct_reverse.size sum += oct_reverse[i].to_i* 8**i end sum end end