From 8175475dd31a9221271fc4a2df7148eb396d5ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=85=B4=E4=BD=B3?= <528070506@qq.com> Date: Tue, 18 Jul 2023 09:10:40 +0000 Subject: [PATCH] =?UTF-8?q?add=20ruby/=E4=B8=80=E4=BA=9B=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E7=9A=84=E6=81=B6=E5=BF=83=E5=86=99=E6=B3=95=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 马兴佳 <528070506@qq.com> --- ...245\345\217\212\344\277\256\346\224\271.md" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "ruby/\344\270\200\344\272\233\350\256\241\347\256\227\347\232\204\346\201\266\345\277\203\345\206\231\346\263\225\344\273\245\345\217\212\344\277\256\346\224\271.md" diff --git "a/ruby/\344\270\200\344\272\233\350\256\241\347\256\227\347\232\204\346\201\266\345\277\203\345\206\231\346\263\225\344\273\245\345\217\212\344\277\256\346\224\271.md" "b/ruby/\344\270\200\344\272\233\350\256\241\347\256\227\347\232\204\346\201\266\345\277\203\345\206\231\346\263\225\344\273\245\345\217\212\344\277\256\346\224\271.md" new file mode 100644 index 0000000..3136bbb --- /dev/null +++ "b/ruby/\344\270\200\344\272\233\350\256\241\347\256\227\347\232\204\346\201\266\345\277\203\345\206\231\346\263\225\344\273\245\345\217\212\344\277\256\346\224\271.md" @@ -0,0 +1,18 @@ + +``` +方法中 a作为除数,b作为被除数 +def division(a,b) + if b > 0 + return (a / b.to_f) + else + return 0 + end +end +``` +可以类似修改如下: +``` +def division(a,b) + a / [b.to_f, 1.0].max +end + +``` \ No newline at end of file -- Gitee