Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 618993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:36:25+00:00 2026-05-13T18:36:25+00:00

With Rails 2.3.5 I’ve written a module in RAILS_ROOT/lib/foo.rb which I’m including in some

  • 0

With Rails 2.3.5 I’ve written a module in RAILS_ROOT/lib/foo.rb which I’m including in some models via “include Foo” and all is well except where I try to use some_object.try(:some_method) in the module code – it throws a NoMethodError rather than returning nil like it would from a Rails model/controller/etc. Do I need to require a Rails file from my module?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:36:25+00:00Added an answer on May 13, 2026 at 6:36 pm

    The try method is added by Rails’ ActiveSupport module, so you need to require active_support within your module.

    Edit: Alternatively, it’s trivial to add it to Object yourself if you don’t want to bring in the whole of ActiveSupport:

    From active_support/lib/active_support/core_ext/object/try.rb:

    class Object
      def try(method, *args, &block)
        send(method, *args, &block)
      end
      remove_method :try
      alias_method :try, :__send__
    end
    
    class NilClass #:nodoc:
      def try(*args)
        nil
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails introduced some core extensions to Ruby like 3.days.from_now which returns, as you'd expect
Rails comes with a handy session hash into which we can cram stuff to
Rails has a nice function, ordinalize , which converts an integer to a friendly
rails 2.3.4, sqlite3 I'm trying this Production.find(:all, :conditions => ["time > ?", start_time.utc], :order
rails-project git:creating-models ❯ rails console Loading development environment (Rails 3.2.1) Couldn't load Wirble: cannot
rails -v ruby -v gem -v all get proper answers. But when I run
Rails, Google maps, Javascript and JSON all at once. So I apologize if this
Rails loads controllers, helpers and models on each request. My controllers have a bunch
Rails newbie here and I'm stumped. In Rails I have a Project Model which
Rails and all my gem files + homebrew installs have been working fine up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.