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
5
votes
4 answers

Is there a method_missing in scala?

similar to the one in Ruby
Jija
  • 995
  • 8
  • 13
5
votes
1 answer

Object#method and dynamic responders

I have a Ruby object (an ActiveRecord object, specifically) named User. It responds to methods like find_by_id, find_by_auth_token, etc. However, these aren't methods that are defined via def or define_method. Instead, they are dynamic methods…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
4
votes
4 answers

Capture method missing in Javascript and do some logic?

In Ruby, you can capture a call to a method which is missing and define it on the fly. What I wanna accomplish in JavaScript is to have an object with no methods. I want a missing method to be translated into a call to emit(): app.isReady() ->…
ajsie
  • 77,632
  • 106
  • 276
  • 381
4
votes
1 answer

Objective-C forwardInvocation:

I often do something like: CoolViewController *coolViewController = [[CoolViewController alloc] init]; [self.navigationController pushViewController:coolViewController animated:YES]; [coolViewController release]; How would I, in a category of…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
4
votes
1 answer

Default Ruby accessor method?

Is there a default method or class accessor that I can add to a Ruby class that get called if a accessor (Ruby like property) doesn't exit? I can then write some custom code to reply from like a array list read from a database where the value can be…
Lennie De Villiers
4
votes
2 answers

Arity of method delegated with method_missing

When I delegate methods on instances of class A to $delegation_target as below: $delegation_target = "" class A def method_missing *args, ≺ $delegation_target.send(*args, &pr) end def respond_to_missing? *args;…
sawa
  • 165,429
  • 45
  • 277
  • 381
4
votes
1 answer

How can I intercept a method call in Boo?

Ruby has method_missing , Python has getattr. Does Boo offer something I can use to intercept method calls?
Geo
  • 93,257
  • 117
  • 344
  • 520
3
votes
9 answers

Ruby - method_missing

I'm trying to implement a method_missing for converting $ to other currencies, as in doing 5.dollars yields 5, 5.yen would yield 0.065 5.euro 6.56 and so on. This I can do now. Now I need to implement it but doing 5.dollars.in(:yen) for…
8vius
  • 5,786
  • 14
  • 74
  • 136
3
votes
1 answer

Why do I get "stack level too deep" from method_missing in irb 1.9.3?

Scenario: -bash-3.2$ irb -f ruby-1.9.3-p0 :001 > @v = {} => {} ruby-1.9.3-p0 :002 > def method_missing(sym, *args); @v[sym]; end => nil ruby-1.9.3-p0 :003 > a (irb):2: stack level too deep (SystemStackError) -bash-3.2$ I ran with -f to avoid…
Kelvin
  • 20,119
  • 3
  • 60
  • 68
3
votes
2 answers

Sum NA across specific columns in R

I have data such as this: data_in <- read_table2("Id Q62_1 Q62_2 Q3_1 Q3_2 Q3_3 Q3_4 Q3_5 1 Yes Sometimes 2 Always 3 4 No Always Yes 5 …
NewBee
  • 990
  • 1
  • 7
  • 26
3
votes
1 answer

Farseer physics...hello world...?

I have no idea why but I cant seem to find out why this isn't working... I'm trying to make something really simple, like something that just falls off the screen. It seems like with the latest download and the first example code on the site, I'm…
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
3
votes
2 answers

Can I get Ruby's method_missing behavior in typescript?

If a class does not implement a method, I want to handle the error raised and inject my own code, using the method name. For example: class Foo { def method_missing(methodName) { console.log(`${methodName} was called`); } } let foo…
Anand
  • 3,690
  • 4
  • 33
  • 64
3
votes
1 answer

VS2015 Unit test project is unable to find a method

I'm getting this error: Result StackTrace: at UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch() Result Message: Test method UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch threw exception: …
Sniipe
  • 115
  • 1
  • 8
3
votes
3 answers

Does powershell have a method_missing()?

I have been playing around with the dynamic abilities of powershell and I was wondering something Is there is anything in powershell analogous to Ruby's method_missing() where you can set up a 'catch all method' to dynamically handle calls to…
Willbill
  • 4,673
  • 6
  • 24
  • 25
3
votes
2 answers

Difficulty aliasing `is_x?` to `has_role? x`

Each user has many roles; to find out whether a user has the "admin" role, we can use the has_role? method: some_user.has_role?('admin') Which is defined like this: def has_role?(role_in_question) …
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
1
2
3
8 9