Last Updated
Viewed 28 Times

I've defined this method on ruby ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14] and (Rails

  def log_method_backtrace
    backtrace = []
    (4..8).map do |i| # 4 because before is ... map, log_method_backtrace...
        b = caller[i][/\/(?:.(?!\/))+$/]
        b = b[1..-2] # *This is the error line
        b = b.sub(':in `', '#')
        backtrace << "#{b} <- "
    log "(Method called from #{backtrace.join})"

When I call it it throw this error:

NoMethodError: undefined method `[]' for nil:NilClass from (pry):5:in `block in log_method_backtrace'

But if I place a debugger breakpoint (I'm using binding.pry) in that line, and run the same line it works.

I have jobs class for ex

class TempJob < ActiveJob::Base
    queue_as :default # To Do Design Queue

    around_perform do |job, block|
        puts "Before Perform'

        puts "After Perform"

    def perform(*args)
        puts "Job Start"

I am trying to schedule job to be execute 1hours from now


but it is giving me following error

NoMethodError: undefined method `perform_at' for TempJob:Class

Using Rails 4.2.0, Ruby 2.2.0, and Sidekiq 3.4.2.

Given Ruby 2.2

module A
  def self.a

How do I access A.a so I can assign to a variable and call it later?

I have tried the following:

x = A::a.to_sym
send x           # NoMethodError: undefined method `a' for main:Object

The following works:

x = -> { A.a }

Since I have both namespaced functions and non namespaced functions in an array is there a way I can do this with send?

I really don't want to pollute the namespace with include A

I just got stuck on this for a while. Take this base:

module Top
  class Test

  module Foo

Later, I can define classes inside Foo that extends Test by doing this:

module Top
  module Foo
    class SomeTest < Test

However, if I try to minimize indentation by using :: to specify the module:

module Top::Foo
  class Failure < Test

This fails with:

NameError: uninitialized constant Top::Foo::Test

Is this a bug, or is it just a logical consequence of the way Ruby resolves variable names?

Similar Question 4 (1 solutions) : Why base class method is being called inside inherited?

Similar Question 7 (2 solutions) : How to refine module method in Ruby?

Similar Question 8 (1 solutions) : rbenv and nokogiri errors on MacOSX