[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 2Q.png (42 KB, 225x225)
42 KB PNG
meme
>>
Ruby can do that.
$ ruby
def method_missing(method_name, *args, &block)
# Check if the missing method call has a single string argument
if args.length == 1 && args.first.is_a?(String)
intended_method = args.first.to_sym

# Check if this intended method exists (such as Kernel's puts or print)
if respond_to?(intended_method, true)
# Invoke the intended method with the method name's string
return send(intended_method, method_name.to_s)
end
end

# Pass to super for normal NoMethodError handling if the pattern doesn't match
super
end

# Example usage:
HelloWorld("puts") # Output: HelloWorld
-:1: warning: redefining Object#method_missing may cause infinite loop
HelloWorld
>>
>>108757096
mods sticky this
>>
someone post fligu gigu



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.