I'm new to Ruby. I'm trying to make some simple calculator program. So, basically what it's supposed to do is you input something like 4+2 and it outputs 6. Simple, right? So I thought. I'm trying to split a string at all the operation characters, so I made this quick regex thinking it would work. It didn't.
class Calculator
def add(a,b)
return a+b
end
def sub(a,b)
return a-b
end
def div(a,b)
return a/b
end
def mul(a,b)
return a*b
end
end
operation = gets.split("[\/\+\-\*]")
print(operation)
sleep()
the sleep() is there to pause the console so I can take a look at my outputs. But right now, it's outputting ["4+2\n"]?? I don't know what I'm doing wrong. I need some help. (it should output ["4","+","2"]). Thanks in advance.