Tod Lazarov
Tod Lazarov

Reputation: 91

syntax error, unexpected tIDENTIFIER, expecting keyword_end after refactoring IF/ELSE

I refactored this code:

if @data.class == Fixnum
  bin_num = @data.to_s(2)
else
  return results
end

To this:

@data.class == Fixnum ? bin_num = @data.to_s(2) : return results

And my program is getting the error in the title. Am I missing something?

Upvotes: 0

Views: 415

Answers (2)

Lukas Baliak
Lukas Baliak

Reputation: 2869

You can use this

return results unless @data.class == Fixnum
bin_num = @data.to_s(2)

Upvotes: 1

gmaliar
gmaliar

Reputation: 5489

try

bin_num = @data.to_s(2) if @data.class == Fixnum or return results

Upvotes: 2

Related Questions