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

Allow unqualified access to Ruby constants in a different module

According to this answer, one can get a constant into the global namespace with an include at the top level, at least in IRB. Naively, I thought I could do the same trick inside a module: module Foo class Bar def frob(val) "frobbed…
David Moles
  • 48,006
  • 27
  • 136
  • 235
3
votes
1 answer

AxHost.GetPictureFromIPicture() method missing, retrieving picture (attachment) from MS Access database

I'm trying to use AxHost.GetPictureFromIPicture() to get a GIF image (saved as an attachment type) from MS Access 2013 database file (*.accdb) - convert it to Image so I can display it in a PictureBox. But the method is not there! :( Am I missing…
Forrest G
  • 31
  • 1
3
votes
1 answer

Ruby. How to know which class instance method is defined?

I want to know which class method_missing is defined. It is defined in Object. How can I figure out which class along the hierarchy overrides it?
Zhang Kai Yu
  • 362
  • 2
  • 8
3
votes
2 answers

Define class methods dynamically in Rails

I define class methods dynamically in Rails as follows: class << self %w[school1 school2].each do |school| define_method("self.find_by_#{school}_id") do |id| MyClass.find_by(school: school, id: id) end end end How can I use…
AdamNYC
  • 19,887
  • 29
  • 98
  • 154
3
votes
1 answer

Defining method_missing on Active record in rails 4 throws SystemStackError: stack level too deep on attributes

I recently upgraded my app to rails 4.0 and ruby 2.0 I'm having problems understanding why my method_missing definitions won't work. I'm pretty sure I'm not doing anything differently than I was before. Specifically, I'm trying to create a method…
rainbowFish
  • 265
  • 3
  • 13
2
votes
1 answer

When might a dispatch table be as good as method_missing in Ruby?

Are there any situations where a dispatch table, implemented as a hash of lambdas, might be as good, if not better, than over-riding Ruby's method_missing? I'm asking because I used this technique today as I'm a comparative newbie with Ruby, but…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
2
votes
1 answer

Stack level too deep when using `method_missing`

I have a dummy object that always yield itself: x = Object.new; x.define_singleton_method(:method_missing) { |*| x } x.foo.bar.baz == x # => true I wanted to simplify it, but suddenly it doesn't work anymore: x = Object.new; def…
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
2
votes
7 answers

method_missing in "Programming Ruby" over my head

method_missing *obj.method_missing( symbol h , args i ) → other_obj Invoked by Ruby when obj is sent a message it cannot handle. symbol is the symbol for the method called, and args are any arguments that were passed to it. The example…
j. parks
  • 23
  • 1
  • 5
2
votes
1 answer

groovy "MissingMethodException" RESTAPI call

I am trying to access data from RESTAPI using groovy code where i am getting error as below: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: () values: [] Possible solutions:…
Symonds
  • 184
  • 1
  • 2
  • 15
2
votes
3 answers

Rails: method_missing is not called on model when using associations

My current code: class Product < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base def method_missing name true end end Category.new.ex_undefined_method #=>…
Tom Maeckelberghe
  • 1,969
  • 3
  • 21
  • 24
2
votes
0 answers

Crystal lang : method_missing for class object?

Something like this? class A module ClassMethods macro method_missing(call) {% p call %} end end extend ClassMethods end A.a Result of the code is Error : undefined method 'a' for A:Class. It seems…
XQY
  • 552
  • 4
  • 17
2
votes
1 answer

custom method_missing ignored if instance is defined via an ActiveRecord association

I have submissions that might be in various states and wrote a method_missing override that allows me to check their state with calls like submission.draft? submission.published? This works wonderfully. I also, for various reasons that might not…
chadoh
  • 4,343
  • 6
  • 39
  • 64
2
votes
2 answers

Rails: "Stack level too deep" error when calling "id" primary key method

This is a repost on another issue, better isolated this time. In my environment.rb file I changed this line: config.time_zone = 'UTC' to this line: config.active_record.default_timezone = :utc Ever since, this…
AmitA
  • 3,239
  • 1
  • 22
  • 31
2
votes
1 answer

Why are some undefined methods (e.g. Foo) not captured by `method_missing`?

I tried to capture undefined methods by the following definition: def method_missing m puts "#{m} is missing" end When I write an undefined method such as foo after it, it is captured by method_missing: foo # => foo is missing but when I write…
sawa
  • 165,429
  • 45
  • 277
  • 381
2
votes
1 answer

Ruby metaprogramming with method_missing to make a HTML DSL

I'm learning metaprogramming and am trying to make a little DSL to generate HTML. The @result instance variable is not generating the correct answer because when the h1 method is called, the @result instance variable is reset. Is there an elegant…
Powers
  • 18,150
  • 10
  • 103
  • 108
1 2
3
8 9