# HG changeset patch # User IBBoard # Date 1506106839 -3600 # Node ID 46a8072897249c0f5dd2efcf0067eb847e76a1ba # Parent 409249712590d02e406bd46935dfb6ece29e28d7 Add a noddy "builder" to show overriding "forward" for missing methods diff -r 409249712590 -r 46a807289724 2-Io/day3-method_missing.io --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2-Io/day3-method_missing.io Fri Sep 22 20:00:39 2017 +0100 @@ -0,0 +1,29 @@ +# Altering "forward" in Io is apparently similar to overriding +# method_missing in Ruby. Except with more to go wrong because +# we have prototypes and not classes. + +# Building arbitrary (basic) XML using a Builder prototype that +# assumes all missing methods are XML tags + +Builder := Object clone + +# This is the dangerous method +Builder forward := method( + writeln("<", call message name, ">") + call message arguments foreach( + arg, + # This will trigger another call to forward + # It's not clear why "writeln" would return a string rather than write to the console + # But apparently it does. Because poorly documented Io. + content := self doMessage(arg) + # No strong type checking here - it's all based on string names + if (content type == "Sequence", writeln(content)) + ) + writeln("") +) + +Builder ul( + li("Obscure"), + li("Undocumented"), + li("Unclear") +) \ No newline at end of file