From 1cf3262cd025df8091bd862f94f1e2391ae73543 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:09:37 +0000 Subject: [PATCH] =?UTF-8?q?add=20ruby/=E4=B8=80=E4=BA=9B=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9C=A8Hash=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E6=93=8D=E4=BD=9C.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 马兴佳 <528070506@qq.com> --- ...5\200\274\347\232\204\346\223\215\344\275\234.md" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "ruby/\344\270\200\344\272\233\344\274\240\345\205\245\347\232\204\345\255\227\347\254\246\344\270\262\345\234\250Hash\345\217\226\345\200\274\347\232\204\346\223\215\344\275\234.md" diff --git "a/ruby/\344\270\200\344\272\233\344\274\240\345\205\245\347\232\204\345\255\227\347\254\246\344\270\262\345\234\250Hash\345\217\226\345\200\274\347\232\204\346\223\215\344\275\234.md" "b/ruby/\344\270\200\344\272\233\344\274\240\345\205\245\347\232\204\345\255\227\347\254\246\344\270\262\345\234\250Hash\345\217\226\345\200\274\347\232\204\346\223\215\344\275\234.md" new file mode 100644 index 0000000..5f180a5 --- /dev/null +++ "b/ruby/\344\270\200\344\272\233\344\274\240\345\205\245\347\232\204\345\255\227\347\254\246\344\270\262\345\234\250Hash\345\217\226\345\200\274\347\232\204\346\223\215\344\275\234.md" @@ -0,0 +1,12 @@ + +``` +例如 params[:key] 传入一个 字符串为 'a' +在方法中 已有hash = {a: '这是A', b: '这是B'} +取值: +JSON.parse(hash.to_json)[params[:key]] +``` +可以类似修改如下: +``` +hash[params[:key].to_sym] + +``` \ No newline at end of file -- Gitee