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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:08:15+00:00 2026-06-09T02:08:15+00:00

Is there some sort of Ruby to_s method that changes a variable to a

  • 0

Is there some sort of Ruby to_s method that changes a variable to a single-quoted string instead of double quotes?

Say I have

date = Time.now
date.to_s

and I want the output to be ‘2012-08-01 22:00:15’. How do I go about doing this? Or is there a method to convert “” strings to ” strings?

Thanks!

EDIT – More Detail

I’m using Rails to display some data in a database. I’ve created the @instanceVar as an array of arrays from my Controller/Model.

<% outer = [] %>
<% inner = [] %>

<% @instanceVar.each do |events| %>
  <% events.each do |event| %>
    <% inner << [event.date, event.total] %>
  <% end %>
  <% outer << inner %>
<% end %>

I need event.date to be a single quoted string.

    <% inner << ['event.date', event.total] %>

just literally adds the words event.date to the array, and

    <% inner << ["#{event.date}", event.total] %>

puts the date in double quotes.

EDIT2

<script>
  $.jqplot('trendingEvents', <%= outer %>,
  {
    #options go here
  });
</script>
  • 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-09T02:08:16+00:00Added an answer on June 9, 2026 at 2:08 am

    Strings are strings in ruby. They are all equal. The only difference is how you declare them (single quotes, double quotes, here-docs and maybe something else). Once you’ve got a string value in a variable, it doesn’t matter how it was declared.

    s1 = 'single quoted'
    s1 # => "single quoted"
    

    So, if your strings don’t leave the rubyland (that is, you don’t render them as javascript or whatever), you shouldn’t worry about the quotes.

    Response to edit 2

    It seems that you have to build your json object in a more manual manner, rather than relying on default behaviour of Array#to_s

    To emit ruby string as javascript single-quoted string literal you can do something like this:

    <script type="text/javascript">
      var s = '<%= ruby_string %>';
    </script>
    

    <%= %> construct will render passed string without quotes. You supply the quotes yourself.

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

Sidebar

Related Questions

Is there some sort of HTML designer (WYSIWYG) available that allows me to draw
So is there some sort of built in checking in Dday iCalendar that checks
... or how does zmq deal with clients that disconnect? Is there some sort
If there is some sort of debugging API that would allow someone to write
Is there some sort of C# directive to use when using a development machine
Is there some sort of exception in Java to catch an invalid Date object?
#foo { color:black; } Is there some sort of option to prefix a newline
What I'm trying to find out is whether there is some sort of equivalence
Is there a way to run some sort of code analysis to find code
Is there any standard way of implementing some sort of a write-through buffer for

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.