⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calculator_controller.rb

📁 RubyonRailsC.zip ruby on rails的源码
💻 RB
字号:
class CalculatorController < ApplicationController
	before_filter :set_charset 
	
	def set_charset 
		@headers["Content-Type"] = "text/html; charset=GB2312" 
	end 
	
	def calculate
		if request.post?
			arg1 = convert_float(:arg1)
			arg2 = convert_float(:arg2)
			op = convert_operator(:operator)
			@result = op.call(arg1, arg2)
		end
	end

	private
	def convert_float(name)
		Float(params[name])
	end

	def convert_operator(name)
		case params[name]
			when "+" then proc {|a,b| a+b}
			when "-" then proc {|a,b| a-b}
			when "*" then proc {|a,b| a*b}
			when "/" then proc {|a,b| a/b}
		end
	end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -