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

  • SEARCH
  • Home
  • 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 8029051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:19:18+00:00 2026-06-05T00:19:18+00:00

I see ruby code that looks like the following. It seems to be some

  • 0

I see ruby code that looks like the following. It seems to be some sort of idiom for creating configuration or settings but I don’t really understand it. Also, how would the Application.configure part of this code look?

MyApp::Application.configure do
  config.something = foo
  config.....
  config....
  .
  config....
end
  • 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-06-05T00:19:19+00:00Added an answer on June 5, 2026 at 12:19 am

    First of all, that configuration way is not specific to Ruby ; it’s the applications (or libraries, gems) that choose to use it or not.

    To explain you what does that code do, I’ll take your snippet as an example:

    MyApp::Application.configure do
      config.something = foo
    end
    

    Here, you are calling MyApp::Application.configure method, with no parameter. After the call, you’re giving it a block.

    You can think of blocks as a piece of code that you can use however you want.
    They can be written in one single line or many:

    { puts 'hello' }
    { |param| puts param } # with passing it a param
    
    # or 
    
    do |param|
      puts param
    end
    

    (remember my_array.each do ... end? It’s a block you pass it. 😉 )

    Now, that block would be called inside the configure method thanks to yield.

    yield uses (or executes) the instructions of the block that has been passed to the method.

    Example: Let’s define a method with a yield inside of it:

    def hello
      puts "Hello #{yield}"
    end
    

    If you call this method, you’d get a 'hello': no block given (yield) (LocalJumpError)'.

    You need to pass it a block: hello { :Samy }.
    The result would then be Hello Samy. As you can see, it simply used what was in the block passed to the method.

    That’s exactly what’s happening in the Rails configuration code. You simply set config.something (config is a method) to some value, and that same config.something = foo is execute inside configure.

    You can learn more about yield and blocks here, and on this great book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C++ Win32 code that I want to call from Ruby. But
I wrote some code that looks like this: def get(x, y) @cachedResults.set(x,y, Math.hypot(x, y))
Whenever I see Ruby code that says: arrayNames.collect { ... } I forget what
I would like to write a code in Ruby that behaves like this C#
Im studying some ruby code and I see this varx variable being used with
I have a block of code that looks like this: def create_page_object(url) begin page
I'm working on some Django-code that has a model like this: class Status(models.Model): code
I have some code that seems to execute improperly when it is serialized and
I'm at the point in learning Ruby where I'd like to look at some
Some code that I had that used attr_accessor_with_default in a rails model is now

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.