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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:57:39+00:00 2026-05-25T22:57:39+00:00

Relevant snippet from test.html: <div id="seat_31F_vacant" class="seatVacant" onclick="UpdateHost(this);Common.DoPostBack(‘lbtPostBack’,’31F’);" onmouseover="Seat_onMouseOver(this)" onmouseout="Seat_onMouseOut(this)">F</div> Now consider this ruby

  • 0

Relevant snippet from test.html:

<div id="seat_31F_vacant" class="seatVacant" onclick="UpdateHost(this);Common.DoPostBack('lbtPostBack','31F');" onmouseover="Seat_onMouseOver(this)" onmouseout="Seat_onMouseOut(this)">F</div>

Now consider this ruby code:

doc = Hpricot(test.html)
  
doc.search("//div[@class='seats']").each do |seat|          
    @vacant_seat += seat.to_s.scan(/id="seat_(.*)_vacant/)
end

@log.info @vacant_seat.to_s

When logging @vacant_seat.to_s this is what I end up with:

[["31F"], ["31E"], ["31D"], ["31C"]] (Using 1.9.2)

31F31E31D31C (Using 1.8.7)

that means if I do @vacant_seat[0].to_s I’ll get:

["31F"] (1.9.2) and 31F (1.8.7)

I want to end up with 31F (as I do with 1.8.7)

Any thougts? Is there a generic way to do this that will work in both Ruby versions? I need to extract the string (eg. 31F) which is located between the underscore characters (_) in the ID attributes. If there is a better way to do this I would appreciate to hear about it.

  • 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-25T22:57:40+00:00Added an answer on May 25, 2026 at 10:57 pm

    Ruby 1.9.2 changed to_s for Arrays. It used to concatenate all of the elements and print them like 31F31E31D31C.

    Now it adds fancy formatting to make it look like an array, so you see the brackets on the arrays, and quotes to the string elements inside of them, so you get [["31F"], ["31E"], ["31D"], ["31C"]].

    It looks like @vacant_seat is an array of arrays, so that’s why @vacant_seat[0].to_s gives you ["31F"].

    If you just need the array that has the elements, then it’s the same array in both, just being printed differently.

    Now, you can use join to call what was to_s in 1.8.7. @vacant_seat.join #=> 31F31E31D31C or @vacant_seat[0].join #=> 31F, will give you what you’re looking for.

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

Sidebar

Related Questions

The relevant snippet of HTML: <span class=a> <div class=fieldname>Question 1</div> <input type=text value= name=q1
This is a HTML snippet from my application: Correct answers: 0 / 6<br /><br
Relevant Code Snippet: public class MyPreference extends Preference { public MyPreference(Context context, AttributeSet attrs)
Given this example document snippet: <html xmlns=http://www.w3.org/1999/xhtml xmlns:zuq=http://localhost/~/zuqml> <head></head> <body> <zuq:data name=a /> <div>
$sidebarEvent = '<h4 class=scheduler_sidebar_link><a href={*URL*}#date={*DATE_SQL*},mode=month target=_blank>{*DATE*}</a></h4> <div class=scheduler_sidebar_text>{*TEXT*}</div>'; This is a snippet from a
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here is the most relevant part of my database schema: create table TEST (
How can I pull relevant packet information from a JpCap packet? I am trying
My Android app has a main WebView (HTML loaded from a local resource) which
I have made a tiny ModX snippet that looks like this <?php $theMenu =

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.