[Note] About the Fizz_Buzz problem (How Ruby on Rails works)

About this article

After creating the PF, when I was entering the Fizz_Buzz problem again in Ruby, I have deepened my understanding a little, so I will leave it as a memorandum.

What is the Fizz_Buzz problem?

The player sits in a circle. The first player says the number "1". The next player speaks the next number of the previous player. However, if it is divisible by 3, it is "Fizz" (in the case of Bizz Buzz, it is "Bizz"), if it is divisible by 5, it is "Buzz", and if it is divisible by both (that is, it is divisible by 15), it is "Fizz Buzz" (Bizz Buzz). If you have to say "Bizz Buzz") instead of a number. Those who make a mistake or hesitate will be dropped out. Posted from Wiki: https://ja.wikipedia.org/wiki/Fizz_Buzz

Writing this programmatically requires conditional branching (if statements, etc.) and repetition (for statements, etc.), so it is often a practice problem for beginners.

fizz_buzz.rb


def fizz_buzz(number)
	if number % 15 == 0
		puts "fuzz_buzz"
	elsif number % 5 == 0
		puts "buzz"
	elsif number % 3 == 0
		puts "fuzz"
	else
		puts number.to_s
	end
end

puts "Please enter a number greater than or equal to 1"
for i in 1..5 do
  print fizz_buzz(gets.to_i)
end

In Ruby on Rails

Look closely at the following programs on the controller

users_controller.rb


def show
	@user = User.find(params[:id])
end

The gets.to_i in fizz_buzz.rb is done in the view file, and the controller processing is executed.

For those who know it, it's natural, but it fell into the prefecture.

that's all

Recommended Posts

[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
A note about the seed function of Ruby on Rails
[Ruby on Rails] about has_secure_password
[Ruby on Rails] How to change the column name
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
How to use Ruby on Rails
[Ruby on Rails] Change the save destination of gem refile * Note
[Ruby on Rails] How to use CarrierWave
[Ruby on Rails] About bundler (for beginners)
part of the syntax of ruby ​​on rails
[Ruby on Rails] About Active Record callbacks
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
[Ruby] FizzBuzz problem
[Ruby] FizzBuzz problem
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to solve the local environment construction of Ruby on Rails (MAC)!
How to debug the processing in the Ruby on Rails model only on the console
[Ruby On Rails] How to search the contents of params using include?
[Ruby on Rails] How to display error messages
[Ruby on Rails] Until the introduction of RSpec
How to add / remove Ruby on Rails columns
[Ruby On Rails] About RubyAws :: Sigv4 :: Errors :: MissingCredentialsError
When the Ruby on Rails terminal rolls back
Publish the app made with ruby on rails
A note about the Rails and Vue process
Determine the current page with Ruby on Rails
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to use session method
[Ruby on Rails] How to make the link destination part of the specified id
How to resolve errors that occur in the "Ruby on Rails" integration test
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
About the [ruby] operator
[Ruby on Rails] How to write enum in Japanese
[Ruby on Rails Tutorial] Error in the test in Chapter 3
Docker the development environment of Ruby on Rails project
(Ruby on Rails6) Reflecting the posted content from the form
(Ruby on Rails6) How to create models and tables
Try using the query attribute of Ruby on Rails
[Ruby on Rails] Implementation of validation that works only when the conditions are met
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
[Ruby on Rails] Only the user who posted can edit
Ruby on rails learning record -2020.10.03
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
about the where method (rails)
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
A note about the scope
[Ruby on Rails] Quickly display the page title in the browser
Ruby on Rails basic learning ①
(Ruby on Rails6) Display of the database that got the id of the database
Ruby on rails learning record-2020.10.07 ②
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Delete all the contents of the list page [Ruby on Rails]
[Ruby on Rails] Automatically enter the address from the zip code
How to display a graph in Ruby on Rails (LazyHighChart)