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 7971263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:35:50+00:00 2026-06-04T07:35:50+00:00

I am new to Ruby. I am familiar with several other languages. My question

  • 0

I am new to Ruby. I am familiar with several other languages. My question is about calling methods out of order. For example:

def myfunction
    myfunction2
end

def myfunction2
    puts "in 2"
end

How could I call myfunction2 before it is declared? Several languages let you declare it at the top or in a .h file. How does ruby handle it?

Do I always need to follow this:

def myfunction2
    puts "in 2"
end

def myfunction
    myfunction2
end

Mainly this bugs me when I need to call another method inside of def initialize for a class.

  • 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-04T07:35:52+00:00Added an answer on June 4, 2026 at 7:35 am

    You can not call a method before you define it. However, that does not mean you can’t define myfunction before myfunction2! Ruby has late binding, so the call to myfunction2 in myfunction will not be associated with the actual myfunction2 before you call myfunction. That means that as long as the first call to myfunction is done after myfunction2 is declared, you should be fine.

    So, this is ok:

    def myfunction
        myfunction2
    end
    
    def myfunction2
        puts "in 2"
    end
    
    myfunction
    

    and this is not:

    def myfunction
        myfunction2
    end
    
    myfunction
    
    def myfunction2
        puts "in 2"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm brand new to ruby and rails and I'm having trouble creating a sign-out
I'm new to ruby, sinatra and padrino, so it might be a silly question,
I am a new Ruby on Rails user and had a question. I have
I'm a new Ruby/Rails guy. Here's one question puzzling me: Can we find the
I'm using the C extension methods to create a new ruby array, but RARRAY_LEN
I am trying to get familiar with the new ruby selenium-webdriver as it appears
Fairly new to ruby. I'm trying to parse a string and assign several variables
I'm currently evaluating options for adding sub-domain support to a new Ruby on Rails
new on ruby and using windows xp and rails 3, i want to send
Im new to ruby, wrote this code and works but i know is not

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.