Sha256: 21dc0312fa3ebc942f5bac1b02e889b3db179df9910d73f9f0461c6eb4149225

Contents?: true

Size: 1.15 KB

Versions: 24

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8
require 'open_classes/string'

# Kernel
module Kernel
  # Print code + eval result
  #
  #   print_eval 8/4, binding  # => 8/4 # => 2
  #   message = 'msg';print_eval "hoge-#{message}", binding # => "hoge-#{message}" # => "hoge-msg"
  def print_eval(code, binding)
    print exec_eval code, binding
  end

  # Puts code + eval result
  #
  #   puts_eval 8/4, binding  # => 8/4 # => 2\n
  #   message = 'msg';puts_eval "hoge-#{message}", binding # => "hoge-#{message}" # => "hoge-msg"\n
  def puts_eval(code, binding)
    puts exec_eval code, binding
  end

  # Puts each-line-code + eval result
  #
  # code
  #   message = 'msg'
  #   puts_eval binding, <<-EOS
  #   "hoge-#{message}1"
  #   "hoge-#{message}2"
  #   EOS
  #
  # result
  #   "hoge-#{message}1" # => "hoge-msg1"\n
  #   "hoge-#{message}2" # => "hoge-msg2"\n
  def bulk_puts_eval(binding, codes)
    result = []
    codes.each_line { |code|result << exec_eval(code.chop, binding) }
    puts result.join("\n").justify_char '#'
  end

  private
  def exec_eval(code, binding)
    ret = eval code, binding
    "#{code} # => #{ret.inspect}"
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.150 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.149 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.148 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.147 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.146 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.145 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.144 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.143 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.142 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.141 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.140 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.139 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.138 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.137 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.136 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.135 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.134 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.133 lib/open_classes/kernel/p_evals.rb
tbpgr_utils-0.0.132 lib/open_classes/kernel/p_evals.rb