looksee 4.4.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/Rakefile +27 -0
- data/ext/extconf.rb +5 -8
- data/ext/mri/3.2.0/id_table.h +36 -0
- data/ext/mri/3.2.0/internal/array.h +162 -0
- data/ext/mri/3.2.0/internal/class.h +212 -0
- data/ext/mri/3.2.0/internal/compilers.h +107 -0
- data/ext/mri/3.2.0/internal/gc.h +188 -0
- data/ext/mri/3.2.0/internal/imemo.h +242 -0
- data/ext/mri/3.2.0/internal/serial.h +23 -0
- data/ext/mri/3.2.0/internal/static_assert.h +16 -0
- data/ext/mri/3.2.0/internal/warnings.h +16 -0
- data/ext/mri/3.2.0/internal.h +113 -0
- data/ext/mri/{2.3.0 → 3.2.0}/method.h +95 -55
- data/ext/mri/mri.c +7 -37
- data/lib/looksee/adapter/base.rb +17 -3
- data/lib/looksee/adapter.rb +0 -1
- data/lib/looksee/clean.rb +1 -3
- data/lib/looksee/core_ext.rb +21 -9
- data/lib/looksee/help.rb +2 -2
- data/lib/looksee/inspector.rb +11 -0
- data/lib/looksee/lookup_path.rb +1 -1
- data/lib/looksee/version.rb +1 -1
- data/spec/looksee/adapter_spec.rb +51 -45
- data/spec/looksee/core_ext_spec.rb +2 -2
- data/spec/looksee/inspector_spec.rb +42 -0
- data/spec/looksee/lookup_path_spec.rb +1 -1
- metadata +15 -13
- data/ext/mri/2.1.0/internal.h +0 -889
- data/ext/mri/2.1.0/method.h +0 -142
- data/ext/mri/2.2.0/internal.h +0 -1182
- data/ext/mri/2.2.0/method.h +0 -141
- data/ext/mri/2.3.0/internal.h +0 -1404
- data/ext/rbx/rbx.c +0 -4
- data/lib/looksee/adapter/rubinius.rb +0 -25
- data/lib/looksee/mri.bundle +0 -0
@@ -1,17 +1,20 @@
|
|
1
|
+
#ifndef RUBY_METHOD_H
|
2
|
+
#define RUBY_METHOD_H 1
|
1
3
|
/**********************************************************************
|
2
4
|
|
3
5
|
method.h -
|
4
6
|
|
5
|
-
$Author
|
7
|
+
$Author$
|
6
8
|
created at: Wed Jul 15 20:02:33 2009
|
7
9
|
|
8
10
|
Copyright (C) 2009 Koichi Sasada
|
9
11
|
|
10
12
|
**********************************************************************/
|
11
|
-
#ifndef RUBY_METHOD_H
|
12
|
-
#define RUBY_METHOD_H 1
|
13
13
|
|
14
14
|
#include "internal.h"
|
15
|
+
#include "internal/imemo.h"
|
16
|
+
#include "internal/compilers.h"
|
17
|
+
#include "internal/static_assert.h"
|
15
18
|
|
16
19
|
#ifndef END_OF_ENUMERATION
|
17
20
|
# if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
|
@@ -33,15 +36,16 @@ typedef enum {
|
|
33
36
|
} rb_method_visibility_t;
|
34
37
|
|
35
38
|
typedef struct rb_scope_visi_struct {
|
36
|
-
rb_method_visibility_t method_visi
|
39
|
+
BITFIELD(rb_method_visibility_t, method_visi, 3);
|
37
40
|
unsigned int module_func : 1;
|
38
41
|
} rb_scope_visibility_t;
|
39
42
|
|
43
|
+
/*! CREF (Class REFerence) */
|
40
44
|
typedef struct rb_cref_struct {
|
41
45
|
VALUE flags;
|
42
|
-
|
43
|
-
|
44
|
-
struct rb_cref_struct *
|
46
|
+
VALUE refinements;
|
47
|
+
VALUE klass_or_self;
|
48
|
+
struct rb_cref_struct * next;
|
45
49
|
const rb_scope_visibility_t scope_visi;
|
46
50
|
} rb_cref_t;
|
47
51
|
|
@@ -49,10 +53,10 @@ typedef struct rb_cref_struct {
|
|
49
53
|
|
50
54
|
typedef struct rb_method_entry_struct {
|
51
55
|
VALUE flags;
|
52
|
-
|
56
|
+
VALUE defined_class;
|
53
57
|
struct rb_method_definition_struct * const def;
|
54
58
|
ID called_id;
|
55
|
-
|
59
|
+
VALUE owner;
|
56
60
|
} rb_method_entry_t;
|
57
61
|
|
58
62
|
typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
|
@@ -65,8 +69,12 @@ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_e
|
|
65
69
|
|
66
70
|
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
67
71
|
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
68
|
-
#define METHOD_ENTRY_COMPLEMENTED(me)
|
69
|
-
#define METHOD_ENTRY_COMPLEMENTED_SET(me)
|
72
|
+
#define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
|
73
|
+
#define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
|
74
|
+
#define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
|
75
|
+
#define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
|
76
|
+
#define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
|
77
|
+
#define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
|
70
78
|
|
71
79
|
static inline void
|
72
80
|
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
@@ -87,32 +95,35 @@ METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsig
|
|
87
95
|
VM_ASSERT(basic <= 1);
|
88
96
|
me->flags =
|
89
97
|
(me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
|
90
|
-
|
98
|
+
((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
|
91
99
|
}
|
92
100
|
static inline void
|
93
101
|
METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
|
94
102
|
{
|
95
103
|
dst->flags =
|
96
104
|
(dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
|
97
|
-
|
105
|
+
(src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
|
98
106
|
}
|
99
107
|
|
100
108
|
typedef enum {
|
101
|
-
VM_METHOD_TYPE_ISEQ,
|
102
|
-
VM_METHOD_TYPE_CFUNC,
|
103
|
-
VM_METHOD_TYPE_ATTRSET,
|
104
|
-
VM_METHOD_TYPE_IVAR,
|
109
|
+
VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
|
110
|
+
VM_METHOD_TYPE_CFUNC, /*!< C method */
|
111
|
+
VM_METHOD_TYPE_ATTRSET, /*!< attr_writer or attr_accessor */
|
112
|
+
VM_METHOD_TYPE_IVAR, /*!< attr_reader or attr_accessor */
|
105
113
|
VM_METHOD_TYPE_BMETHOD,
|
106
114
|
VM_METHOD_TYPE_ZSUPER,
|
107
115
|
VM_METHOD_TYPE_ALIAS,
|
108
116
|
VM_METHOD_TYPE_UNDEF,
|
109
117
|
VM_METHOD_TYPE_NOTIMPLEMENTED,
|
110
|
-
VM_METHOD_TYPE_OPTIMIZED,
|
111
|
-
VM_METHOD_TYPE_MISSING,
|
112
|
-
VM_METHOD_TYPE_REFINED,
|
118
|
+
VM_METHOD_TYPE_OPTIMIZED, /*!< Kernel#send, Proc#call, etc */
|
119
|
+
VM_METHOD_TYPE_MISSING, /*!< wrapper for method_missing(id) */
|
120
|
+
VM_METHOD_TYPE_REFINED, /*!< refinement */
|
113
121
|
|
114
122
|
END_OF_ENUMERATION(VM_METHOD_TYPE)
|
115
123
|
} rb_method_type_t;
|
124
|
+
#define VM_METHOD_TYPE_MINIMUM_BITS 4
|
125
|
+
STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS,
|
126
|
+
VM_METHOD_TYPE_REFINED <= (1<<VM_METHOD_TYPE_MINIMUM_BITS));
|
116
127
|
|
117
128
|
#ifndef rb_iseq_t
|
118
129
|
typedef struct rb_iseq_struct rb_iseq_t;
|
@@ -120,94 +131,123 @@ typedef struct rb_iseq_struct rb_iseq_t;
|
|
120
131
|
#endif
|
121
132
|
|
122
133
|
typedef struct rb_method_iseq_struct {
|
123
|
-
const rb_iseq_t *
|
124
|
-
rb_cref_t *
|
134
|
+
const rb_iseq_t * iseqptr; /*!< iseq pointer, should be separated from iseqval */
|
135
|
+
rb_cref_t * cref; /*!< class reference, should be marked */
|
125
136
|
} rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
|
126
137
|
|
127
138
|
typedef struct rb_method_cfunc_struct {
|
128
139
|
VALUE (*func)(ANYARGS);
|
129
|
-
VALUE (*invoker)(VALUE
|
140
|
+
VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
|
130
141
|
int argc;
|
131
142
|
} rb_method_cfunc_t;
|
132
143
|
|
133
144
|
typedef struct rb_method_attr_struct {
|
134
145
|
ID id;
|
135
|
-
|
146
|
+
VALUE location; /* should be marked */
|
136
147
|
} rb_method_attr_t;
|
137
148
|
|
138
149
|
typedef struct rb_method_alias_struct {
|
139
|
-
|
150
|
+
struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
|
140
151
|
} rb_method_alias_t;
|
141
152
|
|
142
153
|
typedef struct rb_method_refined_struct {
|
143
|
-
|
144
|
-
|
154
|
+
struct rb_method_entry_struct * orig_me;
|
155
|
+
VALUE owner;
|
145
156
|
} rb_method_refined_t;
|
146
157
|
|
147
|
-
typedef struct
|
148
|
-
|
149
|
-
|
150
|
-
|
158
|
+
typedef struct rb_method_bmethod_struct {
|
159
|
+
VALUE proc; /* should be marked */
|
160
|
+
struct rb_hook_list_struct *hooks;
|
161
|
+
VALUE defined_ractor;
|
162
|
+
} rb_method_bmethod_t;
|
163
|
+
|
164
|
+
enum method_optimized_type {
|
165
|
+
OPTIMIZED_METHOD_TYPE_SEND,
|
166
|
+
OPTIMIZED_METHOD_TYPE_CALL,
|
167
|
+
OPTIMIZED_METHOD_TYPE_BLOCK_CALL,
|
168
|
+
OPTIMIZED_METHOD_TYPE_STRUCT_AREF,
|
169
|
+
OPTIMIZED_METHOD_TYPE_STRUCT_ASET,
|
170
|
+
OPTIMIZED_METHOD_TYPE__MAX
|
171
|
+
};
|
172
|
+
|
173
|
+
typedef struct rb_method_optimized {
|
174
|
+
enum method_optimized_type type;
|
175
|
+
unsigned int index;
|
176
|
+
} rb_method_optimized_t;
|
177
|
+
|
178
|
+
struct rb_method_definition_struct {
|
179
|
+
BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS);
|
180
|
+
unsigned int iseq_overload: 1;
|
181
|
+
int alias_count : 27;
|
182
|
+
int complemented_count : 28;
|
183
|
+
unsigned int no_redef_warning: 1;
|
151
184
|
|
152
185
|
union {
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
enum method_optimized_type {
|
161
|
-
OPTIMIZED_METHOD_TYPE_SEND,
|
162
|
-
OPTIMIZED_METHOD_TYPE_CALL,
|
163
|
-
|
164
|
-
OPTIMIZED_METHOD_TYPE__MAX
|
165
|
-
} optimize_type;
|
186
|
+
rb_method_iseq_t iseq;
|
187
|
+
rb_method_cfunc_t cfunc;
|
188
|
+
rb_method_attr_t attr;
|
189
|
+
rb_method_alias_t alias;
|
190
|
+
rb_method_refined_t refined;
|
191
|
+
rb_method_bmethod_t bmethod;
|
192
|
+
rb_method_optimized_t optimized;
|
166
193
|
} body;
|
167
194
|
|
168
195
|
ID original_id;
|
169
|
-
|
196
|
+
uintptr_t method_serial;
|
197
|
+
};
|
198
|
+
|
199
|
+
struct rb_id_table;
|
200
|
+
|
201
|
+
typedef struct rb_method_definition_struct rb_method_definition_t;
|
202
|
+
STATIC_ASSERT(sizeof_method_def, offsetof(rb_method_definition_t, body)==8);
|
170
203
|
|
171
204
|
#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
|
172
205
|
#define UNDEFINED_REFINED_METHOD_P(def) \
|
173
206
|
((def)->type == VM_METHOD_TYPE_REFINED && \
|
174
207
|
UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
|
175
208
|
|
209
|
+
void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
|
176
210
|
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
|
177
211
|
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi);
|
212
|
+
void rb_add_method_optimized(VALUE klass, ID mid, enum method_optimized_type, unsigned int index, rb_method_visibility_t visi);
|
178
213
|
void rb_add_refined_method_entry(VALUE refined_class, ID mid);
|
179
214
|
|
180
|
-
rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
|
181
215
|
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
|
182
216
|
rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def);
|
183
217
|
|
184
218
|
const rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
|
185
219
|
|
186
220
|
const rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
|
187
|
-
const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id);
|
188
|
-
const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id);
|
221
|
+
const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
|
222
|
+
const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
|
189
223
|
const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
|
224
|
+
RUBY_SYMBOL_EXPORT_BEGIN
|
225
|
+
const rb_method_entry_t *rb_resolve_me_location(const rb_method_entry_t *, VALUE[5]);
|
226
|
+
RUBY_SYMBOL_EXPORT_END
|
190
227
|
|
191
228
|
const rb_callable_method_entry_t *rb_callable_method_entry(VALUE klass, ID id);
|
192
|
-
const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id);
|
193
|
-
const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id);
|
194
|
-
const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
|
229
|
+
const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
|
230
|
+
const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
|
195
231
|
|
196
232
|
int rb_method_entry_arity(const rb_method_entry_t *me);
|
197
233
|
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
|
198
234
|
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
|
199
235
|
|
200
236
|
VALUE rb_method_entry_location(const rb_method_entry_t *me);
|
201
|
-
VALUE rb_mod_method_location(VALUE mod, ID id);
|
202
|
-
VALUE rb_obj_method_location(VALUE obj, ID id);
|
203
237
|
|
204
238
|
void rb_free_method_entry(const rb_method_entry_t *me);
|
205
|
-
void rb_sweep_method_entry(void *vm);
|
206
239
|
|
207
240
|
const rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me);
|
208
|
-
const rb_callable_method_entry_t *rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, VALUE defined_class);
|
241
|
+
const rb_callable_method_entry_t *rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class);
|
209
242
|
void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src);
|
210
243
|
|
244
|
+
void rb_method_table_insert(VALUE klass, struct rb_id_table *table, ID method_id, const rb_method_entry_t *me);
|
245
|
+
|
211
246
|
void rb_scope_visibility_set(rb_method_visibility_t);
|
212
247
|
|
248
|
+
VALUE rb_unnamed_parameters(int arity);
|
249
|
+
|
250
|
+
void rb_clear_method_cache(VALUE klass_or_module, ID mid);
|
251
|
+
void rb_clear_method_cache_all(void);
|
252
|
+
|
213
253
|
#endif /* RUBY_METHOD_H */
|
data/ext/mri/mri.c
CHANGED
@@ -1,56 +1,24 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
|
3
|
-
#if RUBY_VERSION
|
4
|
-
# define VM_ASSERT(expr) ((void)0)
|
5
|
-
#endif
|
6
|
-
|
7
|
-
#include "method.h"
|
8
|
-
#include "internal.h"
|
9
|
-
|
10
|
-
#ifndef Looksee_method_table_foreach
|
11
|
-
# define Looksee_method_table_foreach st_foreach
|
12
|
-
# define Looksee_method_table_lookup st_lookup
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#if RUBY_VERSION < 230
|
16
|
-
static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) {
|
17
|
-
# ifdef ID_ALLOCATOR
|
18
|
-
/* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
|
19
|
-
if (method_name == ID_ALLOCATOR)
|
20
|
-
return ST_CONTINUE;
|
21
|
-
# endif
|
22
|
-
|
23
|
-
if (UNDEFINED_METHOD_ENTRY_P(me))
|
24
|
-
rb_ary_push(*names, ID2SYM(method_name));
|
25
|
-
return ST_CONTINUE;
|
26
|
-
}
|
27
|
-
#endif
|
28
|
-
|
3
|
+
#if RUBY_VERSION < 320
|
29
4
|
/*
|
30
5
|
* Return the list of undefined instance methods (as Symbols) of the
|
31
6
|
* given internal class.
|
32
7
|
*/
|
33
8
|
VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) {
|
34
|
-
#if RUBY_VERSION >= 230
|
35
9
|
static int warned = 0;
|
36
10
|
if (!warned) {
|
37
|
-
rb_warn("Looksee cannot display undef-ed methods on MRI 2
|
11
|
+
rb_warn("Looksee cannot display undef-ed methods on MRI < 3.2");
|
38
12
|
warned = 1;
|
39
13
|
}
|
40
14
|
return rb_ary_new();
|
41
|
-
#else
|
42
|
-
VALUE names = rb_ary_new();
|
43
|
-
if (RCLASS_ORIGIN(klass) != klass)
|
44
|
-
klass = RCLASS_ORIGIN(klass);
|
45
|
-
Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
|
46
|
-
return names;
|
47
|
-
#endif
|
48
15
|
}
|
16
|
+
#endif
|
49
17
|
|
50
18
|
VALUE Looksee_singleton_instance(VALUE self, VALUE klass) {
|
51
19
|
if (!SPECIAL_CONST_P(klass) && BUILTIN_TYPE(klass) == T_CLASS && FL_TEST(klass, FL_SINGLETON)) {
|
52
|
-
VALUE object;
|
53
|
-
if (
|
20
|
+
VALUE object = rb_ivar_get(klass, rb_intern("__attached__"));
|
21
|
+
if (object == Qnil)
|
54
22
|
rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object");
|
55
23
|
return object;
|
56
24
|
} else {
|
@@ -63,6 +31,8 @@ void Init_mri(void) {
|
|
63
31
|
VALUE mAdapter = rb_const_get(mLooksee, rb_intern("Adapter"));
|
64
32
|
VALUE mBase = rb_const_get(mAdapter, rb_intern("Base"));
|
65
33
|
VALUE mMRI = rb_define_class_under(mAdapter, "MRI", mBase);
|
34
|
+
#if RUBY_VERSION < 320
|
66
35
|
rb_define_method(mMRI, "internal_undefined_instance_methods", Looksee_internal_undefined_instance_methods, 1);
|
36
|
+
#endif
|
67
37
|
rb_define_method(mMRI, "singleton_instance", Looksee_singleton_instance, 1);
|
68
38
|
}
|
data/lib/looksee/adapter/base.rb
CHANGED
@@ -9,11 +9,11 @@ module Looksee
|
|
9
9
|
start =
|
10
10
|
begin
|
11
11
|
singleton_class = (class << object; self; end)
|
12
|
-
singleton_class unless has_no_methods?(singleton_class) && !(Class === object)
|
12
|
+
singleton_class unless has_no_methods?(singleton_class) && includes_no_modules?(singleton_class) && !(Class === object)
|
13
13
|
rescue TypeError # immediate object
|
14
14
|
end
|
15
15
|
start ||= Looksee.safe_call(Object, :class, object)
|
16
|
-
|
16
|
+
Looksee.safe_call(Module, :ancestors, start)
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
@@ -48,6 +48,14 @@ module Looksee
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
def undefined_instance_methods(mod)
|
52
|
+
if Module.method_defined?(:undefined_instance_methods)
|
53
|
+
mod.undefined_instance_methods
|
54
|
+
else
|
55
|
+
internal_undefined_instance_methods(mod)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
def internal_undefined_instance_methods(mod)
|
52
60
|
raise NotImplementedError, "abstract"
|
53
61
|
end
|
@@ -55,7 +63,13 @@ module Looksee
|
|
55
63
|
def has_no_methods?(mod)
|
56
64
|
[:public, :protected, :private].all? do |visibility|
|
57
65
|
Looksee.safe_call(Module, "#{visibility}_instance_methods", mod, false).empty?
|
58
|
-
end &&
|
66
|
+
end && undefined_instance_methods(mod).empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
def includes_no_modules?(klass)
|
70
|
+
ancestors = Looksee.safe_call(Module, :ancestors, klass)
|
71
|
+
ancestors.size == 1 ||
|
72
|
+
klass.included_modules == klass.ancestors[1].included_modules
|
59
73
|
end
|
60
74
|
|
61
75
|
def singleton_instance(singleton_class)
|
data/lib/looksee/adapter.rb
CHANGED
data/lib/looksee/clean.rb
CHANGED
@@ -18,7 +18,7 @@ module Looksee
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
#
|
21
|
-
# The default options passed to #
|
21
|
+
# The default options passed to #look.
|
22
22
|
#
|
23
23
|
# Default: <tt>[:public, :protected, :private, :undefined,
|
24
24
|
# :overridden]</tt>
|
@@ -165,8 +165,6 @@ module Looksee
|
|
165
165
|
case ruby_engine
|
166
166
|
when 'jruby'
|
167
167
|
self.adapter = Adapter::JRuby.new
|
168
|
-
when 'rbx'
|
169
|
-
self.adapter = Adapter::Rubinius.new
|
170
168
|
else
|
171
169
|
self.adapter = Adapter::MRI.new
|
172
170
|
end
|
data/lib/looksee/core_ext.rb
CHANGED
@@ -3,28 +3,40 @@ module Looksee
|
|
3
3
|
#
|
4
4
|
# Shortcut for Looksee[self, *args].
|
5
5
|
#
|
6
|
-
def
|
6
|
+
def look(*args)
|
7
7
|
Looksee[self, *args]
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.rename(name) # :nodoc:
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if name.is_a?(Hash)
|
12
|
+
warning = "You have renamed Looksee's method with Looksee.rename(#{name.inspect}).\n\n" +
|
13
|
+
"Looksee now uses #look instead of #ls."
|
14
|
+
if name[:ls].to_s == 'look'
|
15
|
+
warn warning << " You can remove this customization."
|
16
|
+
elsif name[:ls]
|
17
|
+
warn warning << " Please rename with Looksee.rename(#{name[:ls].inspect}), or remove this customization."
|
18
|
+
end
|
19
|
+
elsif name.to_s == 'look'
|
20
|
+
warn warning << " You can remove this customization."
|
21
|
+
end
|
22
|
+
|
23
|
+
name = name[:look] || name[:ls] if name.is_a?(Hash)
|
24
|
+
alias_method name, :look
|
25
|
+
remove_method :look
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
17
29
|
#
|
18
|
-
# Rename the #
|
30
|
+
# Rename the #look method, added to every object. Example:
|
19
31
|
#
|
20
|
-
# rename :
|
32
|
+
# rename :_look
|
21
33
|
#
|
22
|
-
# This renames Looksee's #
|
34
|
+
# This renames Looksee's #look method to #_look.
|
23
35
|
#
|
24
36
|
# For backward compatibility, the old-style invocation is also
|
25
|
-
# supported.
|
37
|
+
# supported. This is deprecated, and will shortly be removed.
|
26
38
|
#
|
27
|
-
# rename :
|
39
|
+
# rename :look => :_look
|
28
40
|
#
|
29
41
|
def self.rename(name)
|
30
42
|
ObjectMixin.rename(name)
|
data/lib/looksee/help.rb
CHANGED
@@ -4,7 +4,7 @@ module Looksee
|
|
4
4
|
<<-EOS.gsub(/^ *\|/, '')
|
5
5
|
|== Looksee Quick Reference
|
6
6
|
|
|
7
|
-
| \e[1mobject.
|
7
|
+
| \e[1mobject.look(*specifiers)\e[0m or \e[1mLooksee[object, *specifiers]\e[0m
|
8
8
|
|
|
9
9
|
| Print the methods of \`object\'.
|
10
10
|
|
|
@@ -41,7 +41,7 @@ module Looksee
|
|
41
41
|
| ...
|
42
42
|
| }
|
43
43
|
|
|
44
|
-
| \e[1mobject.
|
44
|
+
| \e[1mobject.look.edit(method)\e[0m
|
45
45
|
|
|
46
46
|
| Jump to the source of the given method. Set your editor
|
47
47
|
| with Looksee.editor or the LOOKSEE_EDITOR environment
|
data/lib/looksee/inspector.rb
CHANGED
@@ -20,6 +20,17 @@ module Looksee
|
|
20
20
|
end.join("\n")
|
21
21
|
end
|
22
22
|
|
23
|
+
def pretty_print(pp)
|
24
|
+
# In the default IRB inspect mode (pp), IRB assumes that an inspect string
|
25
|
+
# that doesn't look like a bunch of known patterns is a code blob, and
|
26
|
+
# formats accordingly. That messes up our color escapes.
|
27
|
+
if Object.const_defined?(:IRB) && IRB.const_defined?(:ColorPrinter) && pp.is_a?(IRB::ColorPrinter)
|
28
|
+
PP.instance_method(:text).bind(pp).call(inspect)
|
29
|
+
else
|
30
|
+
pp.text(inspect)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
23
34
|
#
|
24
35
|
# Open an editor at the named method's definition.
|
25
36
|
#
|
data/lib/looksee/lookup_path.rb
CHANGED
@@ -89,7 +89,7 @@ module Looksee
|
|
89
89
|
methods[method.to_s] = visibility
|
90
90
|
end
|
91
91
|
end
|
92
|
-
Looksee.adapter.
|
92
|
+
Looksee.adapter.undefined_instance_methods(@module).each do |method|
|
93
93
|
methods[method.to_s] = :undefined
|
94
94
|
end
|
95
95
|
methods
|
data/lib/looksee/version.rb
CHANGED
@@ -67,6 +67,14 @@ describe "Looksee.adapter" do
|
|
67
67
|
['[C]', '[Object]', '[BasicObject]', 'Class', 'Module', 'Object', 'Kernel', 'BasicObject']
|
68
68
|
end
|
69
69
|
|
70
|
+
it "should contain entries for modules included in the singleton class" do
|
71
|
+
temporary_module :M
|
72
|
+
c = Object.new
|
73
|
+
c.extend(M)
|
74
|
+
filtered_lookup_modules(c).should ==
|
75
|
+
['[Object instance]', 'M', 'Object', 'Kernel', 'BasicObject']
|
76
|
+
end
|
77
|
+
|
70
78
|
it "should work for immediate objects" do
|
71
79
|
if RUBY_VERSION >= "2.4.0"
|
72
80
|
filtered_lookup_modules(1).first.should == 'Integer'
|
@@ -76,61 +84,59 @@ describe "Looksee.adapter" do
|
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
|
-
describe "
|
87
|
+
describe ".undefined_instance_methods" do
|
80
88
|
def self.target_method(name)
|
81
89
|
define_method(:target_method){name}
|
82
90
|
end
|
83
91
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
92
|
+
if Looksee.ruby_engine == 'ruby' && RUBY_VERSION >= '2.3' && RUBY_VERSION < '3.2'
|
93
|
+
it "just returns an empty array" do
|
94
|
+
temporary_class :C
|
95
|
+
add_methods C, undefined: [:f]
|
96
|
+
@adapter.undefined_instance_methods(C).should == []
|
97
|
+
end
|
98
|
+
else
|
99
|
+
it "should return the list of undefined instance methods directly on a class" do
|
100
|
+
temporary_class :C
|
101
|
+
add_methods(C, undefined: [:f])
|
102
|
+
@adapter.undefined_instance_methods(C).should == [:f]
|
103
|
+
end
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
105
|
+
it "should return the list of undefined instance methods directly on a module" do
|
106
|
+
temporary_module :M
|
107
|
+
add_methods(M, undefined: [:f])
|
108
|
+
@adapter.undefined_instance_methods(M).should == [:f]
|
109
|
+
end
|
103
110
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
111
|
+
it "should return the list of undefined instance methods directly on a singleton class" do
|
112
|
+
temporary_class :C
|
113
|
+
c = C.new
|
114
|
+
add_methods(c.singleton_class, undefined: [:f])
|
115
|
+
@adapter.undefined_instance_methods(c.singleton_class).should == [:f]
|
116
|
+
end
|
110
117
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
118
|
+
it "should return the list of undefined instance methods directly on a class' singleton class" do
|
119
|
+
temporary_class :C
|
120
|
+
add_methods(C.singleton_class, undefined: [:f])
|
121
|
+
@adapter.undefined_instance_methods(C.singleton_class).should == [:f]
|
122
|
+
end
|
116
123
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
124
|
+
it "should not return defined methods" do
|
125
|
+
temporary_class :C
|
126
|
+
C.send(:define_method, :f){}
|
127
|
+
@adapter.undefined_instance_methods(C).should == []
|
128
|
+
end
|
122
129
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
130
|
+
it "should not return removed methods" do
|
131
|
+
temporary_class :C
|
132
|
+
C.send(:define_method, :f){}
|
133
|
+
C.send(:remove_method, :f)
|
134
|
+
@adapter.undefined_instance_methods(C).should == []
|
135
|
+
end
|
129
136
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
137
|
+
it "should handle the MRI allocator being undefined (e.g. Struct)" do
|
138
|
+
struct_singleton_class = (class << Struct; self; end)
|
139
|
+
@adapter.undefined_instance_methods(struct_singleton_class).should == []
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Looksee::ObjectMixin do
|
4
|
-
describe "#
|
4
|
+
describe "#look" do
|
5
5
|
before do
|
6
6
|
@object = Object.new
|
7
7
|
Looksee.stub(:default_specifiers).and_return([])
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return an Inspector for the object's lookup path using the given arguments" do
|
11
|
-
result = @object.
|
11
|
+
result = @object.look(:private)
|
12
12
|
result.should be_a(Looksee::Inspector)
|
13
13
|
result.lookup_path.object.should.equal?(@object)
|
14
14
|
result.visibilities.should == Set[:private]
|