Module: ExploreRb

Defined in:
lib/explore_rb.rb,
lib/explore_rb/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
9
10
11
# File 'lib/explore_rb.rb', line 6

def self.extended base
  puts "Use the following commands to look around:"
  puts "  classes, objects, get_objects, symbols, gems,"
  puts "  local_variables, draw_this, start_garbage_collection"
  puts "  stop_garbage_collection, load_paths, help"
end

Instance Method Details

#classesObject



13
14
15
# File 'lib/explore_rb.rb', line 13

def classes
  (Object.constants - [:RUBY_COPYRIGHT, :RUBY_DESCRIPTION, :RUBY_ENGINE, :RUBY_PATCHLEVEL, :RUBY_PLATFORM, :RUBY_RELEASE_DATE, :RUBY_REVISION, :RUBY_VERSION, :CROSS_COMPILING ]).sort
end

#draw_this(&block) ⇒ Object



39
40
41
42
43
# File 'lib/explore_rb.rb', line 39

def draw_this &block
  path = "#{ENV['HOME']}/Desktop"
  Traceur.watch_paths('.+', path, &block)
  puts "File saved in #{path}."
end

#gemsObject



33
34
35
36
37
# File 'lib/explore_rb.rb', line 33

def gems
  gems = {}
  Gem::Specification.each{|s| gems[s.name]= s.gem_dir.gsub(ENV['HOME'], "~") }
  gems
end

#get_objects(klass) ⇒ Object



23
24
25
26
27
# File 'lib/explore_rb.rb', line 23

def get_objects klass
  requested_klass = []
  ObjectSpace.each_object{|o| requested_klass << ObjectSpace._id2ref(o.object_id) if o.class == klass}
  requested_klass
end

#load_pathsObject



55
56
57
58
59
# File 'lib/explore_rb.rb', line 55

def load_paths
  # $: returns a reference.
  # For demo purposes we want a value.
  Array.new $:
end

#objectsObject



17
18
19
20
21
# File 'lib/explore_rb.rb', line 17

def objects
  objects = Hash.new {0}
  ObjectSpace.each_object{|obj| objects[obj.class] += 1 }
  objects
end

#start_garbage_collectionObject



45
46
47
48
49
# File 'lib/explore_rb.rb', line 45

def start_garbage_collection
  ENV['RUBY_GC_MALLOC_LIMIT']='0'
  GC.stress=true
  GC.start
end

#stop_garbage_collectionObject



51
52
53
# File 'lib/explore_rb.rb', line 51

def stop_garbage_collection
  GC.stress=false
end

#symbolsObject



29
30
31
# File 'lib/explore_rb.rb', line 29

def symbols
  Symbol.all_symbols
end