Questions tagged [method-missing]

The Ruby method that is invoked on an object when you send it a message (or call a method) that it doesn't understand.

The method_missing method is used to respond to methods when you don't know what methods you need to understand until runtime.

124 questions
1
vote
1 answer

Ruby: I need help understanding the following code involving method_missing(method, *args, &block)

I came across this code while trying to learn about creating your own method_missing method, and I don't understand it. What I don't understand are these parts: method_sym[-1] == "=" and method_sym[0..-2] What do they refer to? I tried some…
1
vote
1 answer

How to use method_missing in Ruby

I have a homework problem to create a simple DSL configuration for Ruby. The problem is in method_missing. I need to print out values of keys, but they're printing out automaticaly, not by command. init.rb: require_relative…
user11086399
1
vote
1 answer

Which is correct REPL or command-line?

when i write method missing in Object class i'm getting the output different in each interface. the code is class Object def method_missing(hgh) puts self end end when i use REPL like irb, i get when i use the command line, i get no error,…
1
vote
3 answers

Ruby blocks with method_missing

Note, this is a follow up to my question here. I'm trying to parse the following Tcl code: foo bar { biz buzz } In Tcl, foo is the method name, bar is the argument, and the rest is a "block" to be processed by eval. Now here is my current…
elmt
  • 1,604
  • 14
  • 24
1
vote
2 answers

Use Ruby to parse a Tcl DSL

I would like to be able to parse some Tcl code where arguments are not surrounded by strings. Consider this tcl code: proc foo {name} { puts "Foo --> $name" } foo bar For those unfamiliar with Tcl, foo is the method name and bar is the…
elmt
  • 1,604
  • 14
  • 24
1
vote
3 answers

Ruby "method_missing" Running a method once it was created

I'm trying to implement a code that automatically creates a method if it fits a certain keyword, with the help of method_missing. This works so far: class Add def initialize() @result = "" end def output() puts…
mre
  • 137
  • 11
1
vote
1 answer

Rails: method_missing leads to StackOverflowError

When triggering a call to method_missing on a Rails server running in development mode, it dies with a StackOverflowError. This is a Rails5 on JRuby environment. We are not using multi-threading here. The behavior can be summarized as follows: The…
Kalsan
  • 822
  • 1
  • 8
  • 19
1
vote
1 answer

Objective C Singleton method not available in Swift Interface

I've been looking for documents of reasons of why a singleton method definition in Objective-C class is not available on the Swift interface on Xcode. The Objective-C class is defined like this /** * A general accessor across the sample App to…
Paolo Pascua
  • 123
  • 1
  • 15
1
vote
1 answer

Where should I define method_missing in a Cucumber Ruby framework?

I have a Ruby-Cucumber framework. I need to use the method method_missing to avoid writing a few repetitive functions. Where should I place my method_missing? In any .rb file under the support folder? Or should it go in some different specific file?
Aks..
  • 1,343
  • 1
  • 20
  • 42
1
vote
2 answers

Method_missing not running when it should

I have a Team class in my program and I am trying to use method_missing but instead of running the function when the method doesn't exist, it gives me an error:"undefined method `hawks' for Team:Class (NoMethodError)" My code is as follows: class…
1
vote
1 answer

Global "method_missing" in PHP?

Possible Duplicate: Magic functions __call() for functions? I can implement __call() to provide method_missing behavior in PHP classes. Is there some way to provide the same functionality in the global scope? I want something like this: function…
Jamie Hale
  • 1,529
  • 2
  • 10
  • 21
1
vote
3 answers

ruby: method_missing backtick typo?

I was building a method to send me an email through mutt when my ruby scripts fail. It looks something like this: begin UnknownFunction() rescue subject = 'Error' to_array = ['email@email.com','email2@email.com'] body = "An error…
dukebd711
  • 15
  • 2
1
vote
2 answers

Executing the &block in method_missing in Ruby

I've just began learning about blocks and using method_missing in Ruby classes, and I've noticed the general formula is def method_missing(sym, *args, &block) My question is if it's possible to execute the &block in the output. For example: class…
reichertjalex
  • 121
  • 1
  • 5
1
vote
3 answers

Ruby -- force method_missing *args to be hash?

I want to define a method_missing function for one of my classes, and I want to be able to pass in a hash as the argument list instead of an array. Like this: MyClass::get_by_id {:id => id} MyClass::get_by_id {:id => id, :filters =>…
kid_drew
  • 3,857
  • 6
  • 28
  • 38
1
vote
1 answer

Cannot define method_missing in top Object

When I try define(by loading script&just typing in the pry) method_missing in pry it just exit to console(cmd on windows xp). When I try typing it on the IRB, it goes into infinite loop or when I try loading the script(irb m.rb) it shows something…
Darek Nędza
  • 1,420
  • 1
  • 12
  • 19
1 2 3
8 9