`
Goldice
  • 浏览: 106970 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

#Ruby# Introspect (2)

阅读更多

3. Looking at Classes

 

superclass => get the parent of any particular class

 

ancestors => get both superclasses and mixin modules

 

在Ruby1.9中,任何未指定的class都继承自Object,而Object继承自BasicObject,BasicObject无superclass。

 

4. Looking inside Classes

 

 

class Demo
end

Demo.private_instance_methods(false)
Demo.protected_instance_methods(false)
Demo.public_instance_methods(false)
Demo.singleton_methods(false)
Demo.class_variables
Demo.constants(false)

 

 

5. Calling Mehods Dynamically

 

 

obj.method(sym)    -> method

 

Looks up the named method as a receiver in obj, returning a Method

object (or raising NameError). The Method object acts as a closure in

obj's object instance, so instance variables and the value of self

remain available.

 

 

 

len="hello".method(:length)
len.call # => 5

也可以这样使用:

def double(a)
     2*a
end
method_object = method(:double)
[ 1, 3, 5, 7 ].map(&method_object)

或者:

str = %q{puts "hello".length}

eval str # => 5

 

 

分享到:
评论

相关推荐

    SwiftUI-Introspect:自检SwiftUI的底层UIKit组件

    对SwiftUI的内省 Introspect允许您获取SwiftUI视图的基础UIKit或AppKit元素。 例如,使用Introspect,您可以访问UITableView来修改分隔符,或者访问UINavigationController来自定义选项卡栏。这个怎么运作Introspect...

    ruby-dbus:DBus的Ruby绑定

    Ruby D-Bus 是Linux的进程间通信机制。...upower_object.introspect upower_interface = upower_object["org.freedesktop.UPower"] on_battery = upower_interface["OnBattery"] if on_battery puts "The comput

    Introspect-crx插件

    **如果是这样,Introspect是您的理想扩展!**** Introspect可以做什么? -评估,描述和反思您的日常生活-通过信息丰富的统计信息深入了解您的生活-查看和编辑以前的任何回复-以CSV格式导出数据-使用深色和浅色主题...

    introspect-fun:JavaScript函数自省以检索函数的参数名称

    var introspect = require ( 'introspect-fun' ) ; var noArgs = function ( ) { } ; var withArgs = function ( arg1 , arg2 , hello ) { } ; function withArgsBis ( arg1 , arg2 , arg3 ) { } ; function ...

    introspect.github.io

    introspect.github.io

    dbus-introspect:Bourne Shell脚本反省DBus

    2. **调试应用通信**:当应用无法正确通信时,可以通过检查DBus接口来定位问题。 3. **学习示例代码**:对于新开发者,可以查看输出的XML来了解如何构建DBus调用。 4. **自动化测试**:编写脚本自动测试DBus服务的...

    introspect-typed

    var matchType = require ( 'introspect-typed' ) . matchType ; matchType ( String , 'yes!' ) ; // => true matchType ( Number , 'no...' ) ; // => false 获取匹配器功能 var matchType = require ( '...

    NSDictionary-Introspect:Objective-C 运行时属性自省

    是推荐的安装NSDictionary-Introspect 。 只需Podfile添加到您的Podfile : 播客文件 pod 'NSDictionary-Introspect' 用法 要使用此代码,请覆盖 NSObject 的 description 方法,如下所示: - ( NSString *)...

    npm-cache-introspect:内省你的本地 npm 缓存

    请勿使用:正在进行的工作 这是对制作一个将内省 npm 缓存的模块的探索。 它在当前形式下不可用。 想法 给定一组模块名称和版本约束,该模块将内省本地 npm 缓存,以查看本地缓存中是否存在满足它的模块 ...

    introspect-frontend

    2. **模块化与打包工具**:项目可能使用Webpack或Rollup这样的工具进行模块打包,将分散的JavaScript、CSS和图片文件合并成可部署的静态资源,优化加载效率。 3. **状态管理**:对于大型应用,可能使用Redux(React...

    pytest最新文档

    ##### 6.5 固件可以内省请求测试的上下文 (Fixtures can introspect the requesting test context) - 固件可以访问请求它的测试函数的信息,从而实现更灵活的功能。 ##### 6.6 参数化的固件 (Parametrizing ...

    D-BUS实例讲解

    - 分析`_introspect_parser`的输出格式。 #### 五、使用dbus-glib ##### 5.1 接口描述文件 - **创建**: 编写`.xml`文件来描述接口。 - **生成绑定**: 使用`gdbus-codegen`工具自动生成绑定代码。 ##### 5.2 对象...

    GWT in Action

    GWT's powerful generators can introspect code at compile time and generate new subclasses with additional functionality. This chapter teaches readers how to build such generators and use them to ...

    自检SwiftUI的底层UIKit组件-Swift开发

    对SwiftUI的深入了解Introspect允许您获取SwiftUI视图的基础UIKit或AppKit元素。 例如,使用Introspect,您可以访问UITableView来修改分隔符,或者可以使用UINavigationController来定制customiz Introspect for ...

    ist的matlab代码-contrail-introspect-cli:使ContrailIntrospect输出CLI友好的脚本

    ist的matlab代码转换轨迹 该脚本提供了一个Contrail CLI命令,主要用于对目的进行故障排除。 它从Contrail主要组件(例如控件,配置和comptue(vrouter)节点)提供的自省服务中检索XML输出,并使它们与CLI友好。...

    spring-boot-02-config.zip

    2. 配置文件的作用:修改SpringBoot自动配置的默认值 3. yml的语法 格式:k:(空格)v 表示一对键值对(空格必须有),大小写敏感 以空格的缩进来控制层级关系 4. 可以写入的数据 **字面量**:普通值...

    docker-introspection:Docker 自省 HTTP 服务器

    Docker 内省 API 这是一个小型的 Python HTTP 服务器,它允许从容器内查询有关 Docker 容器的信息,而无需暴露整个 Docker API。 服务器只支持只读访问一种资源——容器信息。 目前没有对请求源的验证。...

    GraphQL Java

    One very important property of GraphQL is that it is statically typed: the server knows exactly the shape of every object you can query and any client can actually "introspect" the server and ask for...

Global site tag (gtag.js) - Google Analytics