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 4.2.5.2)

  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} <- "
    end
    log "(Method called from #{backtrace.join})"
  end

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'

        block.call

        puts "After Perform"
    end

    def perform(*args)
        puts "Job Start"
    end
end

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

TempJob.perform_at(1.hour.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
    "a"
  end
end

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 }
x.call

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
  end

  module Foo
  end
end

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

module Top
  module Foo
    class SomeTest < Test
    end
  end
end

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

module Top::Foo
  class Failure < Test
  end
end

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

cc