fancy-p 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -5
- data/lib/fancy-p/kernel_ext.rb +12 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d21fa983878e6759eddc0db9fec1e940bcd26eda49d69d800c2a9813e448b5
|
4
|
+
data.tar.gz: 14ef6c60f41890099f102476ae46b77d6539b63dc0b32e32aa33f0eb6b9bcf95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fc64b440dfc9d62bfff84c0bf9608d51911444ac81aa3d1cb1de22d7512d6077e3284eb734937896f88df944738481cf7e1c8a98c6c6958dedfec12ec2055a5
|
7
|
+
data.tar.gz: 16e431de47b80efec215e51c3b8104c4818e79539742ba7b037fbb24306b62ee6e4e2e5e30ac374e5acde6e44e34c8b89f2030337a82e35f4d429a2a584f57de
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# fancy-p
|
2
2
|
|
3
3
|
`fancy-p` is a Ruby gem that extends the Kernel module to dynamically define
|
4
4
|
print methods with different characters. It allows you to create methods like
|
@@ -13,9 +13,7 @@ of any length and prints it with a specified special character or str.
|
|
13
13
|
You can also create your own print methods `pf_factory` method.
|
14
14
|
|
15
15
|
|
16
|
-
```ruby
|
17
16
|
## Installation
|
18
|
-
|
19
17
|
Add this line to your application's Gemfile:
|
20
18
|
|
21
19
|
```ruby
|
@@ -28,14 +26,19 @@ gem 'fancy-p'
|
|
28
26
|
require 'fancy-p'
|
29
27
|
|
30
28
|
p! 'Hello, world!'
|
31
|
-
# => "
|
29
|
+
# => "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
32
30
|
# => "Hello, world!"
|
33
|
-
# => "
|
31
|
+
# => "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
34
32
|
|
35
33
|
p1 'Hello, world!'
|
36
34
|
# => "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
|
37
35
|
# => "Hello, world!"
|
38
36
|
# => "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
```rb
|
41
|
+
require 'fancy-p'
|
39
42
|
|
40
43
|
fp "@", "Hello, world!"
|
41
44
|
# => "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
@@ -46,6 +49,10 @@ fp "@", "Hello, world!", length: 14
|
|
46
49
|
# => "@@@@@@@@@@@@@@"
|
47
50
|
# => "Hello, world!"
|
48
51
|
# => "@@@@@@@@@@@@@@"
|
52
|
+
```
|
53
|
+
|
54
|
+
```rb
|
55
|
+
require 'fancy-p'
|
49
56
|
|
50
57
|
print_wat = fp_factory "WAT ", length: 10
|
51
58
|
|
@@ -59,3 +66,22 @@ print_wat['Some other string']
|
|
59
66
|
# => "Some other string"
|
60
67
|
# => "WAT WAT WAT WAT WAT WAT WAT WAT WAT WAT "
|
61
68
|
```
|
69
|
+
|
70
|
+
|
71
|
+
## In a Rails Project
|
72
|
+
|
73
|
+
To automatically load and initialize the gem in a Rails project, follow these steps:
|
74
|
+
|
75
|
+
1. Add the gem to your Gemfile:
|
76
|
+
```ruby
|
77
|
+
gem 'fancy-p'
|
78
|
+
```
|
79
|
+
|
80
|
+
2. Run `bundle install`
|
81
|
+
|
82
|
+
3. Create an initializer file in `config/initializers/fancy_p.rb` and add the following code:
|
83
|
+
```ruby
|
84
|
+
require 'fancy-p'
|
85
|
+
```
|
86
|
+
|
87
|
+
Now you can use the dynamic print methods anywhere in your Rails application, including controllers, models, views, and the Rails console.
|
data/lib/fancy-p/kernel_ext.rb
CHANGED
@@ -4,29 +4,30 @@ module Kernel
|
|
4
4
|
def method_missing(method_name, *args, &)
|
5
5
|
super unless method_name.to_s =~ /^p.$/
|
6
6
|
|
7
|
-
char = method_name.to_s[1]
|
8
7
|
self.class.define_method(method_name) do |*forwarded_args|
|
9
|
-
|
10
|
-
|
11
|
-
p(*forwarded_args)
|
12
|
-
p delimiter
|
8
|
+
char = method_name.to_s[1]
|
9
|
+
print_surrounding(char, *forwarded_args)
|
13
10
|
end
|
14
11
|
send(method_name, *args)
|
15
12
|
end
|
16
13
|
|
14
|
+
def print_surrounding(str, *args, length: 100)
|
15
|
+
delimiter = str * length
|
16
|
+
p delimiter
|
17
|
+
p(*args)
|
18
|
+
p delimiter
|
19
|
+
end
|
20
|
+
|
17
21
|
def fp(str, *args, length: 100)
|
18
|
-
delimiter = str
|
22
|
+
delimiter = str * length
|
19
23
|
p delimiter
|
20
24
|
p(*args)
|
21
25
|
p delimiter
|
22
26
|
end
|
23
27
|
|
24
|
-
def fp_factory(
|
28
|
+
def fp_factory(str, length: 100)
|
25
29
|
lambda { |*args|
|
26
|
-
|
27
|
-
p delimiter
|
28
|
-
p(*args)
|
29
|
-
p delimiter
|
30
|
+
fp(str, *args, length:)
|
30
31
|
}
|
31
32
|
end
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy-p
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rhodes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
This gem extends the Kernel module to dynamically define
|