[intro]You've completed Surviving APIs with Rails and earned the final completion badge.[/intro] I just finished this course from codeschool and it is really cool btw I have created a public repository in my account it is actually working https://github.com/heridev/rails-simple-api-example I learnt very useful things in this course, but...
Hello guys, when you are working at crowdint.com, one of the most appreciated skills in a developer is when you enjoy to refactor your code all the time and in this little example I'm will share with all of you, about how to stop or avoid using if else conditionals in Ruby, so let's start.
Before the refactor [ruby] class Calculator attr_accessor :number_one, :number_two def initialize number_one, number_two @number_one = number_one @number_two = number_two end def calculate if @number_one == 5 and @number_two == 8 puts "Are equal to 5 and 8: #{@number_one} and #{@number_two}" else puts "Are different to 5 and 8: #{@number_one} and #{@number_two}" end end end calculator = Calculator.new 5, 8 calculator.calculate [/ruby]