当前位置: 首页 > news >正文

ruby send call 的简单使用

refer: ruby on rails - What does .call do? - Stack Overflow

Ruby使用call 可以调用方法或者proc

m = 12.method("+")
# => `method` gets the `+` method defined in the `Fixnum` instance
# m.class 
# => Methodm.call(3)    #=> 15
# `3` is passed inside the `+` method as argument 
m.call(20)   #=> 32

send方法也可以调用方法,在本地写一个测试:

def say_hiputs "hihi"enddef say_goodbyeputs "goodbye"end# 使用send方式调用方法name = "say_hi"send(name)m = 12.method("+")# => `method` gets the `+` method defined in the `Fixnum` instance# m.class# => Methodm.call(3)    #=> 15puts m.call(3)# `3` is passed inside the `+` method as argumentm.call(20)   #=> 32puts m.call(20)

运行:ruby hi.rb

得到输出:

hihi1532

http://www.lryc.cn/news/118214.html

相关文章:

  • 24聊城大学823软件工程考研
  • 勘探开发人工智能技术:机器学习(3)
  • 定制 ChatGPT 以满足您的需求 自定义说明
  • taro h5列表拖拽排序 --- sortablejs 和 react-sortable-hoc
  • Linux的shell脚本常用命令
  • 使用自己的数据集预加载 Elasticsearch
  • 机器视觉赛道持续火热,深眸科技坚持工业AI视觉切入更多应用领域
  • MyBatis操作数据库常见用法总结2
  • 基于SpringBoot+LayUI的宿舍管理系统 001
  • C语言笔记7
  • Centos更换网卡名称为eth0
  • 【Express.js】软件测试
  • TCP三次握手、四次握手过程,以及原因分析
  • OceanBase X Flink 基于原生分布式数据库构建实时计算解决方案
  • 600V EasyPIM™ IGBT模块FB30R06W1E3、FB20R06W1E3B11、FB20R06W1E3降低了系统成本和损耗,可满足高能效要求。
  • form 表单恢复初始数据
  • MySQL—索引
  • Android图形-合成与显示-概论
  • Swift 5 数组如何获取集合的索引和对应的元素值
  • 计算 Nginx 日志的PV和UV
  • Spring中常用的注解
  • Plugin 插件
  • Structure needs cleaning fsimage文件系统损坏修复
  • MATLAB|信号处理的Simulink搭建与研究
  • LinuxC编程——线程
  • 使用fetch调用fastapi接口(post)的实例
  • 探索规律:Python地图数据可视化艺术
  • Django-------自定义命令
  • 【Linux】在浏览器输入网址后发生了什么事情?
  • 推荐两本书《JavaRoadmap》、《JustCC》