如何乘以“5x3"红宝石字符串? [英] How to multiply "5x3" string in ruby?

查看:25
本文介绍了如何乘以“5x3"红宝石字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何乘以这个字符串:5x3"并得到整数形式的总数?

How may I multiply this string: "5x3" and get the total as integer?

推荐答案

我的理念倾向于将其转换为数据结构,使用我们拥有的用于处理数据结构的强大工具,然后在必要时转换回来".

My philosophy tends to be "get it into a data structure, use the great tools we have for working with data structures, then convert back if necessary".

"5x3".split('x').map(&:to_i).reduce(&:*)

这篇关于如何乘以“5x3"红宝石字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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