lazy_string 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/LICENSE.txt +1 -1
- data/README.txt +4 -5
- data/lazy_string.gemspec +1 -1
- data/lib/lazy_string.rb +8 -9
- metadata +10 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b95d72633b9419e5306c154c7adda01b3ea723d39d4bf3ee58b41111371bc128
|
4
|
+
data.tar.gz: 2fde23cece3bb04dec3570ab777fd8cf6528024dc1ead33ac2d6dae9d8fde974
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea1f4d2c963a844fe677fdf59bf866b8ce33a323997357f243301640f79fb73dc15f45e7ff456db8274120de018a96d7aa36a5d782186299855ba9123e60699
|
7
|
+
data.tar.gz: 375eb324a2af06e24b661eabce5e674420eb476f33a8165b457123dacb86fbf67148a391d8f24f4839e480b517f8d4be11899e8944283c570fc71e3e8da0de6d
|
data/LICENSE.txt
CHANGED
data/README.txt
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
LazyString
|
2
2
|
|
3
|
-
LazyString is a Ruby class for computing strings only when necessary
|
4
|
-
|
5
|
-
|
6
|
-
a method argument, for example.
|
3
|
+
LazyString is a Ruby class for computing strings only when necessary. This is
|
4
|
+
useful when computing the string is expensive but the string is unlikely to be
|
5
|
+
used: an error message passed as an argument, for example.
|
7
6
|
|
8
7
|
Thanks to duck typing and Ruby's standard conversion protocols, you can pass
|
9
8
|
an instance of LazyString to many methods that ask for a string.
|
@@ -17,7 +16,7 @@ file, you can create a lazy string by passing a block to LazyString.new:
|
|
17
16
|
ls = LazyString.new { "answer = #{expensive_computation}" }
|
18
17
|
|
19
18
|
The block (and therefore expensive_computation) will not be called immediately.
|
20
|
-
But later, if #to_str or #to_s is
|
19
|
+
But later, if #to_str or #to_s is sent to the lazy string, the block will be
|
21
20
|
called with no arguments in order to create the real string.
|
22
21
|
|
23
22
|
# String interpolation calls #to_s automatically.
|
data/lazy_string.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = 'lazy_string'
|
8
8
|
gem.version = LazyString::VERSION
|
9
9
|
gem.authors = ['Aaron Beckerman']
|
10
|
-
gem.description = %q{This library provides LazyString, a class for computing strings only when necessary
|
10
|
+
gem.description = %q{This library provides LazyString, a class for computing strings only when necessary. This is useful when computing the string is expensive but the string is unlikely to be used: an error message passed as an argument, for example.}
|
11
11
|
gem.summary = %q{A Ruby library for lazily computing strings.}
|
12
12
|
gem.license = 'MIT'
|
13
13
|
gem.required_ruby_version = '>= 1.8.7'
|
data/lib/lazy_string.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
##
|
2
|
-
# LazyString is a class for computing strings only when necessary
|
3
|
-
# when
|
4
|
-
#
|
5
|
-
# a method argument, for example.
|
2
|
+
# LazyString is a class for computing strings only when necessary. This is
|
3
|
+
# useful when computing the string is expensive but the string is unlikely to
|
4
|
+
# be used: an error message passed as an argument, for example.
|
6
5
|
#
|
7
6
|
class LazyString
|
8
7
|
##
|
9
8
|
# The version string.
|
10
9
|
#
|
11
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.4.0'
|
12
11
|
|
13
12
|
##
|
14
13
|
# Creates a new lazy string. The block argument will be saved for later use
|
@@ -29,10 +28,10 @@ class LazyString
|
|
29
28
|
##
|
30
29
|
# Returns the computed string. It will compute the string by calling (with no
|
31
30
|
# arguments) the block passed to ::new. If the block's return value responds
|
32
|
-
# to the \to_str message, \to_str will be
|
33
|
-
# Otherwise, \to_s will be
|
34
|
-
# so subsequent
|
35
|
-
# again.
|
31
|
+
# to the \to_str message, \to_str will be sent to it to create the string.
|
32
|
+
# Otherwise, \to_s will be sent to it. The computed string will be saved,
|
33
|
+
# so subsequent invocations of this method will not cause the block to be
|
34
|
+
# called again.
|
36
35
|
#
|
37
36
|
def to_str
|
38
37
|
@str ||= begin
|
metadata
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Beckerman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'This library provides LazyString, a class for computing strings only
|
14
|
-
when necessary
|
15
|
-
|
16
|
-
|
17
|
-
email:
|
14
|
+
when necessary. This is useful when computing the string is expensive but the string
|
15
|
+
is unlikely to be used: an error message passed as an argument, for example.'
|
16
|
+
email:
|
18
17
|
executables: []
|
19
18
|
extensions: []
|
20
19
|
extra_rdoc_files: []
|
@@ -24,11 +23,11 @@ files:
|
|
24
23
|
- lazy_string.gemspec
|
25
24
|
- lib/lazy_string.rb
|
26
25
|
- test/lazy_string_test.rb
|
27
|
-
homepage:
|
26
|
+
homepage:
|
28
27
|
licenses:
|
29
28
|
- MIT
|
30
29
|
metadata: {}
|
31
|
-
post_install_message:
|
30
|
+
post_install_message:
|
32
31
|
rdoc_options: []
|
33
32
|
require_paths:
|
34
33
|
- lib
|
@@ -43,9 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: '0'
|
45
44
|
requirements: []
|
46
|
-
|
47
|
-
|
48
|
-
signing_key:
|
45
|
+
rubygems_version: 3.3.7
|
46
|
+
signing_key:
|
49
47
|
specification_version: 4
|
50
48
|
summary: A Ruby library for lazily computing strings.
|
51
49
|
test_files:
|