鲁比:空白?没有导轨 [英] Ruby: blank? without Rails

查看:23
本文介绍了鲁比:空白?没有导轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这个测试:

if (line.blank?) do_stuff

...但我是纯红宝石,而不是导轨.实现相同效果的公认习惯用法是什么?

...but I'm in straight ruby, not rails. What's the accepted idiom for accomplishing the same effect?

我正在为一个字符串执行此操作,其中测试 .empty 吗?与测试 .blank 不一样吗?(全空白字符串不是空的,而是空白的.)

I'm doing this for a string, where testing for .empty? is not the same as testing for .blank? (An all whitespace string is not empty, but is blank.)

推荐答案

来自 ActiveSupport

line !~ /[^[:space:]]/

这篇关于鲁比:空白?没有导轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆