y_support 2.0.28 → 2.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/y_support/unicode.rb +60 -41
- data/lib/y_support/version.rb +1 -1
- data/test/unicode_test.rb +23 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0bd1b8b70060322aaea75ad11f07890adef799e
|
4
|
+
data.tar.gz: 9918e56fbed551dd5051067d92af30e3a4cd9e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0275a6c4b90096fcc9299e7bd1bed593319045e46818b9a848dd67bf84f3b1f8463dd75177856ffc46cd54efe2d53c5d88e10c8b8337c2a7b2d1c2b3f90936bd
|
7
|
+
data.tar.gz: fdeb2cbfe9c079b0d493c13557c72ad6dc909d7a9329bf7ad605ae3202ad52bcfcb6b82b16df29d5fa4ec4d0669c0161e8b7cc4748e2cfa3e57b107893d2c733
|
data/lib/y_support/unicode.rb
CHANGED
@@ -2,70 +2,89 @@
|
|
2
2
|
|
3
3
|
require 'y_support'
|
4
4
|
|
5
|
-
#
|
5
|
+
# A tiny number of Unicode 1-character aliases:
|
6
6
|
#
|
7
|
-
# * <b>ç</b> – class (c with cedilla, U00E7
|
8
|
-
# * <b>ⓒ</b> – singleton class (copyright sign
|
9
|
-
# * <b
|
10
|
-
# * <b
|
7
|
+
# * <b>ç</b> – class (c with cedilla, U00E7)
|
8
|
+
# * <b>ⓒ</b> – singleton class (copyright sign)
|
9
|
+
# * <b>√</b> – square root
|
10
|
+
# * <b>Σ</b> – summation
|
11
|
+
# * <b>Π</b> – product
|
11
12
|
#
|
12
|
-
# It is also encouraged that other on-letter Unicode abbreviations are
|
13
|
-
# used especially for local variables:
|
14
|
-
#
|
15
|
-
# * <b>ɱ</b> – module (m with hook, U2C6E, compose seq. [m, j])
|
16
|
-
# * <b>ꜧ</b> – hash (latin small letter heng, UA727, compose seq. [h, j])
|
17
|
-
# * <b>ᴀ</b> – array (small capital A, U1D00, compose seq. [a, `])
|
18
|
-
# * <b>ß</b> – symbol (German sharp s, U00DF, compose seq. [s, s])
|
19
|
-
# * <b>ς</b> – string (Greek final sigma, U03C2, compose seq. [*, w])
|
20
|
-
# * <b>w</b> – abbreviation for "with"
|
21
|
-
# * <b>wo</b> – abbreviation for "without"
|
22
|
-
#
|
23
|
-
# There are, however, no defined methods using these in YSupport. In other
|
24
|
-
# words, using these additional abbreviations is completely up to the goodwill
|
25
|
-
# of the developer.
|
26
|
-
#
|
27
|
-
# ==== Note on compose sequences
|
28
|
-
#
|
29
|
-
# Each compose sequence has to be preceded by pressing the <compose> key.
|
30
|
-
# The compose sequences comply with the standard Kragen's .XCompose file
|
31
|
-
# (https://github.com/kragen/xcompose). In some cases, the needed characters
|
32
|
-
# are not in Kragen's file and need to be defined manually.
|
33
|
-
#
|
34
13
|
class Object
|
35
14
|
alias :ç :class
|
36
|
-
alias
|
37
|
-
alias :© :singleton_class
|
38
|
-
|
39
|
-
# Square root (proxy for Math.sqrt(x)).
|
40
|
-
#
|
41
|
-
def √( number ); Math.sqrt( number ) end
|
15
|
+
alias ⓒ singleton_class
|
42
16
|
|
43
17
|
# Sum. The argument is expected to be a collection; block can be specified.
|
44
18
|
# Basically same as chaining .reduce( :+ ) to the end; Σ() notation can be
|
45
19
|
# more readable at times.
|
46
20
|
#
|
47
|
-
def
|
21
|
+
def Σ( collection )
|
48
22
|
collection.reduce { |acc, element|
|
49
23
|
acc + ( block_given? ? yield( element ) : element )
|
50
24
|
}
|
51
25
|
end
|
52
|
-
alias :Σ :∑
|
53
26
|
|
54
27
|
# Product. The argument is expected to be a collection; block can be specified.
|
55
28
|
# Basically same as chaining .reduce( :* ) to the end; Π() notation can be
|
56
29
|
# more readable at times.
|
57
30
|
#
|
58
|
-
def
|
31
|
+
def Π( collection )
|
59
32
|
collection.reduce { |acc, element|
|
60
33
|
acc * ( block_given? ? yield( element ) : element )
|
61
34
|
}
|
62
35
|
end
|
63
|
-
alias :Π :∏
|
64
36
|
end
|
65
37
|
|
38
|
+
|
39
|
+
# Defined aliases:
|
40
|
+
#
|
41
|
+
# * <b>★</b> – alias for include
|
42
|
+
# * <b>ç</b> for +class+ in several method names
|
43
|
+
#
|
66
44
|
class Module
|
67
|
-
alias
|
68
|
-
|
69
|
-
alias
|
70
|
-
alias
|
45
|
+
alias ★ include
|
46
|
+
|
47
|
+
alias ç_variable_set class_variable_set
|
48
|
+
alias ç_variable_get class_variable_get
|
49
|
+
alias ç_variable_defined? class_variable_defined?
|
50
|
+
alias remove_ç_variable remove_class_variable
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# Defined aliases
|
56
|
+
#
|
57
|
+
# * <b>√</b> – root of arbitrary degree ( x.√( n ) is n ** ( 1 / x ) ).
|
58
|
+
# * <b>sqrt</b> as in +4.sqrt+ for square root (Math#sqrt).
|
59
|
+
#
|
60
|
+
class Numeric
|
61
|
+
def √ number
|
62
|
+
number ** ( 1.0 / self )
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# Square root (using Math#sqrt).
|
67
|
+
#
|
68
|
+
def sqrt
|
69
|
+
Math.sqrt( self )
|
70
|
+
end
|
71
71
|
end
|
72
|
+
|
73
|
+
|
74
|
+
# Other abbreviations (eg. for local variables) are optionally encouraged:
|
75
|
+
#
|
76
|
+
# * <b>ɱ</b> – module (m with hook, U2C6E, compose seq. [m, j])
|
77
|
+
# * <b>ꜧ</b> – hash (latin small letter heng, UA727, compose seq. [h, j])
|
78
|
+
# * <b>ᴀ</b> – array (small capital A, U1D00, compose seq. [a, `])
|
79
|
+
# * <b>ß</b> – symbol (German sharp s, U00DF, compose seq. [s, s])
|
80
|
+
# * <b>ς</b> – string (Greek final sigma, U03C2, compose seq. [*, w])
|
81
|
+
# * <b>w</b> – abbreviation for "with"
|
82
|
+
# * <b>wo</b> – abbreviation for "without"
|
83
|
+
#
|
84
|
+
# Note on compose sequences:
|
85
|
+
#
|
86
|
+
# Each compose sequence is preceded the <compose> key, whose location depends
|
87
|
+
# on your system configuration. The sequences above comply with the standard
|
88
|
+
# Kragen's .XCompose file (https://github.com/kragen/xcompose). In some cases,
|
89
|
+
# the characters not in Kragen's file have to be defined manually for
|
90
|
+
# comfortable typing.
|
data/lib/y_support/version.rb
CHANGED
data/test/unicode_test.rb
CHANGED
@@ -1,33 +1,30 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
# require 'y_support/all'
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/autorun'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
describe "y_support/unicode" do
|
8
|
+
before do
|
9
|
+
require 'y_support/unicode'
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
12
|
+
it "should define a tiny number of Unicode aliases" do
|
13
|
+
o = Object.new
|
14
|
+
assert o.singleton_class == o.ⓒ
|
15
|
+
assert o.ç == o.class
|
16
|
+
assert 10 == Σ(1..4)
|
17
|
+
assert 24 == Π(1..4)
|
18
|
+
2.must_equal 4.sqrt
|
19
|
+
3.√( 8 ).must_equal 2
|
20
|
+
ɱ = Module.new
|
21
|
+
ɱ.ç_variable_set :@@meaning, 42
|
22
|
+
assert ɱ.class_variable_get( :@@meaning ) == 42
|
23
|
+
assert ɱ.ç_variable_get( :@@meaning ) == 42
|
24
|
+
assert ɱ.ç_variable_defined?( :@@meaning )
|
25
|
+
ɱ.remove_ç_variable :@@meaning
|
26
|
+
assert ! ɱ.ç_variable_defined?( :@@meaning )
|
27
|
+
ɱ.module_exec { ★ Comparable }
|
28
|
+
assert ɱ < Comparable
|
32
29
|
end
|
33
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|