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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:21:14+00:00 2026-06-18T16:21:14+00:00

In Sinatra application I have a code gef ‘/123’ do @var1 = # some

  • 0

In Sinatra application I have a code

gef '/123' do
  @var1 = # some calculations
  @var2 = # some calculations
  #..... many of them

  haml(:"view123")
end

and all of the instance variables are used in view123. I wonder, will there be any benefit of using the hash instead of many variables like this:

gef '/123' do
  hash_var = {}
  hash_var[:var1] = # some calculations
  hash_var[:var2] = # some calculations
  #..... many of them

  haml(:"view123")
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-18T16:21:15+00:00Added an answer on June 18, 2026 at 4:21 pm

    I think you are on the right track, and it’s hard to advise in this very abstract sense, but in general that # some calculations looks like business logic. And business logic belongs in models.

    How about a model instead? Make a new class that performs these calculations, then instantiate it and pass the instance to your view. Your controller/route handler remains lean and clean, and many many lines of calculations are all tucked into a file dedicated to just that thing. Neat and tidy.

    get '/123' do
      @calc = CrazyCalculator.new
      haml(:view123)
    end
    

    view123.erb:

    <ul>
      <li>Calc1: <%= @calc.calc1 %></li>
      <li>Calc2: <%= @calc.calc2 %></li>
      <li>Calc3: <%= @calc.calc3 %></li>
      <li><!-- many other calculation methods --></li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Sinatra-based application and have seen some apps using an environment.rb file
I have a Sinatra application I've created and I'd like to package it as
I have a variable in my Sinatra application: get '/' do @agenda_date = Date.today
I'm having problems settig up my application using Thin and Sinatra. I have created
I am trying to do some silly automatic configuration of a Sinatra application which
I have a Sinatra application and a method get '/page123' do string1\nstring2 end If
I have a Sinatra application hosted with Unicorn, and nginx in front of it.
I have a Sinatra application and DRb server object paired. When I try to
I run a sinatra application with mongomapper. I have models called Movie(Document) and Cover(EmbeddedDocument).
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application

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.