print_variable 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pv.rb +35 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5402b51f2051e8ef4e7e72b78f616e70179a9c3d
|
4
|
+
data.tar.gz: bfb03b81bb193bd309657fa85e12dd48de2ce93d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afa91c8338eb21367fb48a578499bb4ff648d190d18e5e54527ddb837d12ed60efd25036dfae4b81b326aa27b9f6a5e65a044d3ea3a312ad8ed00243604940d6
|
7
|
+
data.tar.gz: 042a748e63a5eaef795ad7813454c230f2f19e7eeb4936655b166ed9bdf99aa3fd771f073713ff7b93b9800478bc2fb46ce2baa07ed34fe0801697e0544df895
|
data/lib/pv.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Print variable with variable name & variable value.
|
5
|
+
#
|
6
|
+
##
|
7
|
+
# == Usage
|
8
|
+
#
|
9
|
+
# var = 1
|
10
|
+
# var2, var_foo, v = 2, 3, 4
|
11
|
+
#
|
12
|
+
# pv{:var} #=> var = 1
|
13
|
+
# pv{%i(var2 var_foo v)} #=> var2 = 2
|
14
|
+
# # var_foo = 3
|
15
|
+
# # v = 4
|
16
|
+
#
|
17
|
+
def pv(&block)
|
18
|
+
ret = block.call
|
19
|
+
|
20
|
+
symbols = if ret.is_a?(Symbol)
|
21
|
+
[ret]
|
22
|
+
elsif ret.is_a?(Array) and ret.all?{|x| x.is_a?(Symbol)}
|
23
|
+
ret
|
24
|
+
else
|
25
|
+
raise "Given block must return Symbol or Array only includes Symbol"
|
26
|
+
end
|
27
|
+
|
28
|
+
varname_length = symbols.map{|symbol| symbol.to_s.length}.max
|
29
|
+
|
30
|
+
symbols.each do |symbol|
|
31
|
+
puts "#{symbol.to_s.ljust(varname_length)} = #{block.binding.eval(symbol.to_s)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
ret
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: print_variable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- diaphragm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Add usefull method to inspect variable.
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/pv.rb
|
20
|
+
homepage: https://github.com/diaphragm/ruby-print-variable
|
21
|
+
licenses:
|
22
|
+
- Apache
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Print variable with variable name & variable value.
|
44
|
+
test_files: []
|