`
zhaoningbo
  • 浏览: 609553 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ruby的逻辑运算符and与&&

    博客分类:
  • os
阅读更多
ruby中,and与&&是有区别的,而且不在“短路”运算上。看例子:
puts true and false
puts (true and false)
puts true && false
puts true & false
////~>
true
false
false
false

翻资料发现ruby1.8.7有这么个说法:
引用

Use &&/|| for boolean expressions, and/or for control flow. (Rule of thumb: If you have to use outer parentheses, you are using the wrong operators.)
2
1
分享到:
评论
1 楼 ipenglei 2014-10-20  
优先级的区别 :

puts true and false  #相当于 (puts true) and false  
puts (true and false)  
puts true && false  #相当于 puts (true && false)
puts true & false  #相当于 puts (true & false)


加括号吧

相关推荐

    Ruby语言教程&案例&相关项目资源

    Ruby语言教程&案例&相关项目资源 Ruby语言教程&案例&相关项目资源 Ruby语言教程&案例&相关项目资源

    Ruby语言教程&案例&相关项目资源分享.docx

    Ruby语言教程&案例&相关项目资源分享.docx

    Ruby的运算符和语句优先级介绍

    虽然 Ruby 一直把最小惊讶原则作为它的哲学之一,但还是常常看到让人惊讶不已,难于理解的代码,这可能是因为对它运算符和语句优先级理解不透导致,今天就和大家聊一聊 Ruby 运算符和语句的优先级。 先看一句简单的...

    ruby_on_rails&radrails环境配置.pdf

    ruby rails radrails 环境 配置 图片加文字教你如何配置开发环境

    02Ruby 运算符.docx

    Ruby是一种动态、面向对象的编程语言,它具有简洁、易读的语法,被称为“程序员最好的朋友”。Ruby具有强大的元编程能力,允许开发者在运行时动态修改和生成代码。Ruby还有一个强大的标准库,提供了丰富的工具和功能...

    ruby and watir 安装指南

    EXECUTABLE DIRECTORY: c:/ruby/bin - RUBYGEMS PLATFORMS: - ruby - x86-mswin32-60 - GEM PATHS: - c:/ruby/lib/ruby/gems/1.8 - C:/Documents and Settings/Administrator/.gem/ruby/1.8 - GEM CONFIGURATION: -...

    Ruby Performance Optimization, Why Ruby is Slow, and How to Fix It

    Ruby Performance Optimization: Why Ruby is Slow, and How to Fix It By 作者: Alexander Dymo ISBN-10 书号: 1680500694 ISBN-13 书号: 9781680500691 Edition 版本: 1 出版日期: 2015-11-29 pages 页数: (202) ...

    Eric is a full featured Python and Ruby editor and IDE,

    Eric is a full featured Python and Ruby editor and IDE, written in python. It is based on the cross platform Qt gui toolkit, integrating the highly flexible Scintilla editor control. It is designed to...

    Ruby语言入门教程&代码示例.pdf

    Ruby语言入门教程&代码示例.pdfRuby语言入门教程&代码示例.pdf

    Ruby的教程.txt

    运算符与控制流:掌握Ruby中的运算符(如算术运算符、比较运算符、逻辑运算符等),以及控制流语句(如条件语句、循环语句等)。 函数与模块:学习如何定义和使用函数,了解模块的概念和用法,实现代码的复用和...

    Ruby语言入门教程&代码示例.zip

    Ruby语言入门教程&代码示例.zipRuby语言入门教程&代码示例.zipRuby语言入门教程&代码示例.zip

    [Ruby] Ruby 1.9 & 2.0 编程 (英文版)

    [Pragmatic Bookshelf] Ruby 1.9 & 2.0 编程 (英文版) [Pragmatic Bookshelf] Programming Ruby 1.9 & 2.0 The Pragmatic Programmers' Guide 4th Edition (E-Book) ☆ 出版信息:☆ [作者信息] Dave Thomas , ...

    Ruby on Rails and J2EE

    Ruby on Rails and J2EE

    Data Structures and Algorithms in Ruby azw3

    Data Structures and Algorithms in Ruby 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    java党建平台源码-ruby_resource:ruby&rails学习资源汇总

    与多态](Polymorphism and Ruby) 书籍推荐 由于 ruby 和 rails 的版本迭代都很快,这就导致很多出版的 ruby 书籍过了几年都严重落伍,所以一定要看要买最新版的。 本书由 ruby 作者参与撰写,入门必读书籍! Ruby ...

    Ruby语言 SendCloud邮件发送 模板发送&&地址列表

    SendCloud Ruby模板发送&&地址列表代码示例,注:此为使用 SendCloud API V2 发送邮件的示例.

    Ruby Under a Microscope

    just a matter of typing ruby at the command line and pressing enter, and your Ruby script is running. However, Ruby’s syntax is deceptively simple; in fact, Ruby employs sophisticated ideas from ...

    Ruby Programming Language 2008 pdf

    The Ruby Programming Language is the authoritative guide to Ruby and provides comprehensive coverage of versions 1.8 and 1.9 of the language. It was written (and illustrated!) by an all-star team: ...

Global site tag (gtag.js) - Google Analytics