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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:03:42+00:00 2026-05-26T19:03:42+00:00

a = [2,4,5] a.count-1 => 2 a.count – 1 => 2 But a.count -1

  • 0
a = [2,4,5]
a.count-1 => 2
a.count - 1 => 2

But

a.count -1 => 0

What causes this behavior? Why doesn’t it happen if a is an integer (and not an array)?

Also, I have noticed that there must not be a space between a method name and the parenthesis that follows (for parameters). Why is that?

Ruby 1.9.2

  • 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-26T19:03:43+00:00Added an answer on May 26, 2026 at 7:03 pm

    Because methods can be called with no parentheses, this:

    a.count - 1
    

    Means subtract 1 from a.count, whereas

    a.count -1 # is like a.count(-1)
    

    Means call the method a.count with -1 as an argument. It doesn’t happen when a is an integer because integers don’t have the count method. You just have to be careful as you type.

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

Sidebar

Related Questions

Dim count As Integer For count = 1 To 10 Step 1 Dim But+count
I need to count the number of elements in an XML file that have
How can I count the number of elements in an array, because contrary to
I count MySQL rows using this function: function sqlcount($table) { $sql = mysql_query(SELECT COUNT(0)
SELECT count(*) FROM Table1 t1 SELECT count(*) FROM Table1 t1 Where t1.ID not in
if( count( $_POST ) < 1 ) { // determine if this was a
I'm trying to count the number of chars in a char array including the
how do we count idential values on after appending value in to array such
count = 0 def fibonacci(n): global count count = count + 1 if not
SELECT COUNT(*) AS cnt FROM products WHERE ExternalProductId IS NOT NULL GROUP BY SourceId,

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.