Class: LazyProxy
- Inherits:
-
Object
show all
- Defined in:
- ext/lazy_proxy/lazy_proxy.c
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
104
105
106
107
108
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 104
static VALUE lp_method_missing(int argc, VALUE* argv, VALUE self) {
VALUE method_name = *argv, obj = lp_get_resolv(self);
return rb_funcallv_public(obj, SYM2ID(method_name), --argc, ++argv);
}
|
Instance Method Details
#__getobj__ ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 44
static VALUE lp_get_resolv(VALUE self) {
struct wrapped_object * ptr = lp_ptr(self);
if (lp_is_unresolved_blk(ptr))
lp_resolve(ptr);
return ptr->obj;
}
|
#__reset__ ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 66
static VALUE lp_reset(VALUE self) {
struct wrapped_object * ptr = lp_ptr(self);
if(!ptr->isblk)
rb_raise(rb_eArgError, "proxy was not provided with a block");
ptr->resolved = 0;
return Qtrue;
}
|
#__setobj__(*args) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 53
static VALUE lp_initialize(int argc, VALUE* argv, VALUE self) {
VALUE arg, blk;
rb_check_arity(argc, 0, 1);
arg = (argc == 1) ? *argv : Qnil;
blk = rb_block_given_p() ? rb_block_proc() : Qnil;
lp_set(self, arg, blk, NIL_P(arg) && !NIL_P(blk));
return self;
}
|
#inspect ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 81
static VALUE lp_inspect(VALUE self) {
VALUE str, cname = rb_obj_class(self);
struct wrapped_object * ptr = lp_ptr(self);
if (lp_is_unresolved_blk(ptr))
str = rb_sprintf("#<%"PRIsVALUE": %+"PRIsVALUE" (unresolved)>", rb_class_path(cname), ptr->blk);
else
str = rb_sprintf("#<%"PRIsVALUE": %+"PRIsVALUE">", rb_class_path(cname), ptr->obj);
return str;
}
|
#send(*args) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'ext/lazy_proxy/lazy_proxy.c', line 93
static VALUE lp_send(int argc, VALUE* argv, VALUE self) {
VALUE obj;
ID method_id;
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
obj = lp_get_resolv(self);
method_id = rb_to_id(*argv);
return rb_funcall2(obj, method_id, --argc, ++argv);
}
|