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

The Archive Base Latest Questions

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

So, I have this ruby file and I want to use it in my

  • 0

So, I have this ruby file and I want to use it in my rails project, but I don’t have a clue on where or how to start, I’ve read about include and require, some sites tell me to use require, some to use include, and even to use both, but that’s it. I would like to know where to put the necessary code, how to use the file’s methods and where to put the file in the project directory, because I want to call it from a view but I don’t know if that is the best, I’m sorry if this is a dumb question but rails is still new for me. I appreciate all the help you can offer. Thanks for your time.

The file I’m trying to use is the one that converts numbers to words created by Faustino Vasquez limon and it’s a full class:

numeros.rb

class Numlet

  def initialize(numero)

    @numero = numero.to_s.reverse.split("")
    @i = 0
    @j = 0
    @parte1 = []
    @parte2 = []
    @especial = ""
    @numlet = []
    @bandera=0
    @bandera1=0
    @a =[["Uno","Dos","Tres","Cuatro","Cinco","Seis","Siete","Ocho","Nueve"],
      ["Diez","Veinte","Treinta","Cuarenta","Cincuenta","Sesenta","Setenta","Ochenta","Noventa"],       
      ["Ciento","Doscientos","Trescientos","Cuatrocientos","Quinientos","Seiscientos","Setecientos","Ochocientos","Novecientos"]]

  end


  def especial 

    @numlet[@j]  = case @especial
    when "11"then  "Once"
    when "12"then  "Doce"
    when "13"then  "Trece"
    when "14"then  "Catorce"
    when "15"then  "Quice"
    when "16"then  "Dieciseis"
    when "17"then  "Diecisiete"
    when "18"then  "Dieciocho"
    when "19"then  "Diecinueve"
    when "21"then  "Veintiun"
    when "22"then  "Veintidos"
    when "23"then  "Veintitres"
    when "24"then  "Veinticuatro"
    when "25"then  "Veinticinco"
    when "26"then  "Veintiseis"
    when "27"then  "Veintisite"
    when "28"then  "Veintiocho"
    when "29"then  "Veintinueve"
    else return 0
    end
  end

  def repetir

    case @numero.length
    when 0..3 then @parte1[0] = @numero[0..@numero.length]
    when 4..6 then @parte1[0] = @numero[0..2];@parte1[1] = @numero[3..@numero.length]
    when 7..9 then @parte1[0] = @numero[0..2];@parte1[1] = @numero[3..5]; @parte1[2] = @numero[6..@numero.length]
    else return 0
    end
  end

  def convierte

    @bandera1=0
    @i=0
    case @bandera
    when 1 then @numlet[@j]="mil";@j+=1
    when 2 then (@parte2.length==1 and @parte2[0]==1) ? @numlet[@j]="millon" : @numlet[@j]="millones";@j+=1
    end
    @especial = [@parte2[@i+1],@parte2[@i]].to_s
    if especial != 0
      @i+=2
      @j+=1
    else
      if @parte2[@i].to_s =="1"
        @numlet[@j]="Un"
        @i+=1
        @j+=1
      end
    end
    while @i < @parte2.length
      if @parte2[@i].to_i ==0
        @i+=1
        @bandera1+=1
      else
        if @parte2.length != 1 and @bandera1 ==0
          if @i == 1
            @numlet[@j]="y"
            @j+=1
          end
        end
        @numlet[@j] = @a[@i][@parte2[@i].to_i-1]
        if  @i == 2  and @bandera1==2 and @numlet[@j]=="Ciento"
          @numlet[@j]="Cien"
        end
        @j+=1
        @i+=1    
      end
    end
    @bandera+=1
  end

  def termina

    @numlet.reverse.join(" ")
  end

  def a_letra

    if  repetir != 0
      @parte1.each do |@parte2|
        convierte
      end
        print "#{termina}\n"
    else
      print "Este numero no puede ser convertido\n"
    end

   end

end

That is what i want to use from my app. Thank you for your time.

  • 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:26:03+00:00Added an answer on June 18, 2026 at 4:26 pm

    Since it’s your own class and you want to use it in one of the Rails views, there’s many ways of using that code.

    My own way and you may or may not choose to do it this way would be to include that file in the lib directory and then require it in the helper file of the you view you want to include it in.

    This would allow you to access methods and initializers from that file and you would be able to create methods in your helpers to use on your views.

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

Sidebar

Related Questions

In a my project in Ruby On Rails (but this is not important), when
The default in Ruby on Rails is to have this set to false (in
I'm new on both this site and ruby on rails! I have a common
I saw this post Ruby on Rails - Awesome nested set plugin but I
I am writing a form in Ruby on Rails and want to have a
I'm completely new to Ruby on Rails, have never worked on it, but I
I want to use partials in rails along with single-table inheritance. I currently have
I have a js.erb file in which I want to use asset_path. It is
I am trying use neo4j with Ruby on rails on Mac OSX. I have
I have a project rails 3.1 in production environment. This is my deploy.rb now:

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.