You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thinking over ways to express this a bit more clearly.
Current API:
deftesting(a,b,c)raise'heck'ifa.is_a?(Numeric) && a > 20d=5ifc.is_a?(Numeric) && c > 3a + b + cendtesting_spy=TraceSpy::Method.new(:testing)do |spy|
# On the arguments, given as keywords, will yield arguments to the blockspy.on_argumentsdo |m|
m.when(a: String,b: String,c: String)do |v|
puts"Oh hey! You called me with strings: #{v}"endm.when(a: 1,b: 2,c: 3)do |v|
puts"My args were 1, 2, 3: #{v}"endend# On an exception, will yield exception to the blockspy.on_exceptiondo |m|
m.when(RuntimeError)do |e|
puts"I encountered an error: #{e}"endend# On a return value, will yield the return to the blockspy.on_returndo |m|
m.when(String)do |v|
puts"Strings in, Strings out no?: #{v}. I got this in though: #{spy.current_arguments}"endm.when(:even?)do |v|
puts"I got an even return: #{v}"endend# On a local variable being present:spy.on_localsdo |m|
m.when(d: 5)do |v|
puts"I saw d was a local in here!: #{v}. I could also ask this: #{spy.current_local_variables}"endendend
Thinking over ways to express this a bit more clearly.
Current API:
Proposed ideas:
The problem is that some branch types are incompatible with eachother.
exception
handlers, for instance, cannot get arguments:https://bugs.ruby-lang.org/issues/15568
That said, exceptions or warnings could be raised in this case.
The main idea of this change is to condense the API down into something more minimal you could hammer our in a REPL.
The text was updated successfully, but these errors were encountered: