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.

119 questions
26
votes
4 answers

Python equivalent of Ruby's 'method_missing'

What is Python's equivalent of Ruby's method_missing method? I tried using __getattr__ but this hook applies to fields too. I only want to intercept the method invocations. What is the Python way to do it?
missingfaktor
  • 86,952
  • 56
  • 271
  • 360
22
votes
15 answers

Are there equivalents to Ruby's method_missing in other languages?

In Ruby, objects have a handy method called method_missing which allows one to handle method calls for methods that have not even been (explicitly) defined: Invoked by Ruby when obj is sent a message it cannot handle. symbol is the symbol for the…
Justin Ethier
  • 122,367
  • 49
  • 219
  • 273
15
votes
2 answers

Ruby’s “method_missing” in Python

Possible Duplicate: Python equivalent of Ruby's 'method_missing' Is there any technique available in Python for intercepting messages (method calls) like the method_missing technique in Ruby?
Zeck
  • 6,045
  • 18
  • 67
  • 105
13
votes
1 answer

Ruby: why does puts call to_ary?

I'm learning metaprogramming in Ruby and am just trying out defining missing methods via method_missing and define_method. I'm getting some unexpected behaviour and am wondering if anyone can explain this. Here is my class: class X def…
Tom De Leu
  • 7,676
  • 3
  • 27
  • 29
12
votes
5 answers

What prevents a statically typed language from having something like Ruby's method_missing?

I don't have much experience with statically typed languages (currently learning Scala and loving it!) but one thing I've noticed is that they don't ever seem to have anything like Ruby's method_missing or ColdFusion's onMissingMethod. Is there some…
Dustin Martin
  • 1,227
  • 2
  • 12
  • 22
11
votes
4 answers

Does Ruby have a method_missing equivalent for undefined instance variables?

When I invoke a method that doesn't exist, method_missing will tell me the name of the method. When I attempt to access a variable that hasn't been set, the value is simply nil. I'm attempting to dynamically intercept access to nil instance…
meager
  • 209,754
  • 38
  • 307
  • 315
11
votes
1 answer

Is there a "method_missing" for rake tasks?

If my Rakefile does not find a task with a particular name, I'd like rake to instead create a new task by that name according to certain rules, if a file with the missing task name exists. But if it doesn't, I want to fall back to the default…
James Wenton
  • 163
  • 4
9
votes
2 answers

Objective C and magic methods in class

Does objective-c offer a way to intercept calls to class method that does not exist?
mgamer
  • 12,296
  • 23
  • 84
  • 142
9
votes
2 answers

How to compose modules containing method_missing in ruby

I have a couple of modules that extend method missing: module SaysHello def respond_to?(method) super.respond_to?(method) || !!(method.to_s =~ /^hello/) end def method_missing(method, *args, &block) if (method.to_s =~…
David Miani
  • 14,178
  • 2
  • 42
  • 63
7
votes
2 answers

Ruby, get hours, seconds and time from Date.day_fraction_to_time

I've found this method here. start = DateTime.now sleep 15 stop = DateTime.now #minutes puts ((stop-start) * 24 * 60).to_i hours,minutes,seconds,frac = Date.day_fraction_to_time(stop-start) I have the following error: `
': private…
dierre
  • 6,900
  • 11
  • 67
  • 115
6
votes
1 answer

Method-missing difficulties in C# 4.0: dynamic vs RealProxy

Does anyone know of a way to intercept dynamic method calls (particularly those that are going to raise RuntimeBinderExceptions) with a RealProxy? I was hoping to catch the exception and implement 'method missing' on top of that, but it appears to…
Thom
  • 2,584
  • 2
  • 28
  • 32
6
votes
3 answers

Is it possible to replicate Ruby's method_missing in Lua?

I'm fairly sure that in Lua, you can use a given metatable's __index, __newindex, and __call to roughly replicate Ruby's method_missing. And I somewhat have: function method_missing(selfs, func) local meta = getmetatable(selfs) local f …
Wesley Wigham
  • 242
  • 2
  • 7
5
votes
2 answers

Using method missing in Rails

I have a model with several date attributes. I'd like to be able to set and get the values as strings. I over-rode one of the methods (bill_date) like so: def bill_date_human date = self.bill_date || Date.today date.strftime('%b %d, %Y') …
5
votes
1 answer

Doesn't Lua have something comparable to Ruby's method_missing?

I seem to recall Lua has something similar to Ruby's method_missing. Or am I remembering incorrectly?
Dexygen
  • 11,681
  • 11
  • 73
  • 144
5
votes
2 answers

Missing Value in Data Analysis

I have a data set in which the variable GENDER containing two levels Male(M) and Female(F) has lot of Missing values . How do i deal with missing value? What are the different methods to handle these missing values. Any help would be appreciated.
1
2 3 4 5 6 7 8