[Ruby笔记]16.Ruby 判断数字 .is_a?(Numeric) .to_i
2016-05-29 08:39
288 查看
使用.is_a?(Numeric)
PS C:\Users\Administrator\RubyCode> irb --simple-prompt >> 100.is_a?(Numeric) => true
使用.to_i
num.rb,如果输入数据是数字,乘以
100再进行
to_i转换还是等于该数值乘以
100的:
def num?(amount) if (amount * 100).to_i == amount * 100 puts "The number is #{amount}" else puts "Number, please!" end end
打开
irb:
PS C:\Users\Administrator\RubyCode> irb --simple-prompt >> load 'num.rb' => true >> num?(100) The number is 100 => nil >> num?('hello') Number, please!
Test if a string is basically an integer in quotes using Ruby?
https://stackoverflow.com/questions/1235863/test-if-a-string-is-basically-an-integer-in-quotes-using-rubyreference
《The Well-Grounded Rubyist, Second Edition》(https://www.manning.com/books/the-well-grounded-rubyist-second-edition)
3.3. Setter methods
眠いよ・・・ /ヽ、 /__ヾ ~(ηω=)ノ ~( ×) ∪∪ http://emoji.vis.ne.jp/neruyo_3koma1.htm[/code]
相关文章推荐
- 红宝石(Ruby)史话
- Ruby简明教程之循环语句介绍
- ruby 一些简单的例子
- Ruby on Rails在Ping ++ 平台实现支付
- Ruby 之 class 中的 private、 protected、public
- Ruby中操作文件的方法介绍
- Ruby中的集合编写指南
- CentOS 6.3下编译安装Ruby 2.0笔记
- Ruby基本的环境变量设置以及常用解释器命令介绍
- 详解Ruby中的代码块及其参数传递
- Ruby编程中关于中断和返回的用法教程
- Ruby中的异常处理代码编写示例
- Ruby程序中发送基于HTTP协议的请求的简单示例
- Ruby中的变量学习总结
- 几个加速Ruby on Rails的编程技巧
- Ruby配置rspec和RestClient来检测服务器
- 分析Cache 在 Ruby China 里面的应用情况
- Ruby中数组的一些相关使用方法
- 编写Ruby代码注释时需要注意的一些问题