Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
symbol.c
Go to the documentation of this file.
1 #include "mruby.h"
2 #include "mruby/khash.h"
3 #include "mruby/array.h"
4 
5 typedef struct symbol_name {
6  size_t len;
7  const char *name;
9 
11 
12 /*
13  * call-seq:
14  * Symbol.all_symbols => array
15  *
16  * Returns an array of all the symbols currently in Ruby's symbol
17  * table.
18  *
19  * Symbol.all_symbols.size #=> 903
20  * Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink,
21  * :chown, :EOFError, :$;, :String,
22  * :LOCK_SH, :"setuid?", :$<,
23  * :default_proc, :compact, :extend,
24  * :Tms, :getwd, :$=, :ThreadGroup,
25  * :wait2, :$>]
26  */
27 static mrb_value
28 mrb_sym_all_symbols(mrb_state *mrb, mrb_value self)
29 {
30  khiter_t k;
31  mrb_sym sym;
32  khash_t(n2s) *h = mrb->name2sym;
33  mrb_value ary = mrb_ary_new_capa(mrb, kh_size(h));
34 
35  for (k = kh_begin(h); k != kh_end(h); k++) {
36  if (kh_exist(h, k)) {
37  sym = kh_value(h, k);
38  mrb_ary_push(mrb, ary, mrb_symbol_value(sym));
39  }
40  }
41 
42  return ary;
43 }
44 
45 void
47 {
48  struct RClass *s = mrb->symbol_class;
49  mrb_define_class_method(mrb, s, "all_symbols", mrb_sym_all_symbols, MRB_ARGS_NONE());
50 }
51 
52 void
54 {
55 }