Skip to content

Instantly share code, notes, and snippets.

@Freika
Created April 23, 2019 10:32
Show Gist options
  • Save Freika/62bce856246210ec2389be6140696daf to your computer and use it in GitHub Desktop.
Save Freika/62bce856246210ec2389be6140696daf to your computer and use it in GitHub Desktop.
class BinaryCalc
def initialize(arg1, arg2, operation)
@arg1 = arg1.to_s
@arg2 = arg2.to_s
@operation = operation == 'plus' ? :+ : :-
end
def call
(@arg1.to_i(2).public_send(@operation, @arg2.to_i(2)).to_s(2))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment