Skip to content

Commit

Permalink
Use new syntax for ruby 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed Nov 9, 2015
1 parent eb31ff2 commit 9ebb625
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 55 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Non yet.

## Changes

* 2015-11-09 Release 1.7.0
- Officially require ruby >= 2.0 and use new hash syntax.

* 2015-08-13 Release 1.6.0
- Add complete method for readline completion
* 2015-06-21 Release 1.5.4
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ GemHadar do
readme 'README.md'
licenses << 'MIT'

required_ruby_version '>= 2.0'
development_dependency 'test-unit', '~>2.5'
end
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.0
1.7.0
8 changes: 4 additions & 4 deletions lib/tins/file_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class << self
attr_accessor :default_options
end
self.default_options = {
:offset => 0,
:buffer_size => 2 ** 13,
:percentage_binary => 30.0,
:percentage_zeros => 0.0,
offset: 0,
buffer_size: 2 ** 13,
percentage_binary: 30.0,
percentage_zeros: 0.0,
}

# Returns true if this file is considered to be binary, false if it is not
Expand Down
12 changes: 6 additions & 6 deletions lib/tins/proc_prelude.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ def call(obj, &my_proc)
def array
lambda { |*list| list }
end
memoize_function :array, :freeze => true
memoize_function :array, freeze: true

def first
lambda { |*list| list.first }
end
memoize_function :first, :freeze => true
memoize_function :first, freeze: true

alias head first

def second
lambda { |*list| list[1] }
end
memoize_function :second, :freeze => true
memoize_function :second, freeze: true

def tail
lambda { |*list| list[1..-1] }
end
memoize_function :tail, :freeze => true
memoize_function :tail, freeze: true

def last
lambda { |*list| list.last }
end
memoize_function :last, :freeze => true
memoize_function :last, freeze: true

def rotate(n = 1)
lambda { |*list| list.rotate(n) }
Expand All @@ -53,7 +53,7 @@ def rotate(n = 1)
def id1
lambda { |obj| obj }
end
memoize_function :id1, :freeze => true
memoize_function :id1, freeze: true

def const(konst = nil, &my_proc)
konst ||= my_proc.call
Expand Down
2 changes: 1 addition & 1 deletion lib/tins/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Tins
# Tins version
VERSION = '1.6.0'
VERSION = '1.7.0'
VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
Expand Down
6 changes: 3 additions & 3 deletions tests/blank_full_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_blank
assert Set[].blank?
assert !Set[23].blank?
assert({}.blank?)
assert !{ :foo => 23 }.blank?
assert !{ foo: 23 }.blank?
assert "".blank?
assert " ".blank?
assert !"foo".blank?
Expand All @@ -29,7 +29,7 @@ def test_present
assert !Set[].present?
assert Set[23].present?
assert !{}.present?
assert({ :foo => 23 }.present?)
assert({ foo: 23 }.present?)
assert !"".present?
assert !" ".present?
assert "foo".present?
Expand All @@ -44,7 +44,7 @@ def test_full
assert_nil Set[].full?
assert_equal Set[23], Set[23].full?
assert_nil({}.full?)
assert_equal({ :foo => 23 }, { :foo => 23 }.full?)
assert_equal({ foo: 23 }, { foo: 23 }.full?)
assert_nil "".full?
assert_nil " ".full?
assert_equal "foo", "foo".full?
Expand Down
4 changes: 2 additions & 2 deletions tests/extract_last_argument_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def test_argument_array_without_options
end

def test_argument_array_witt_options
arguments = [ 1, 2, 3, { :foo => :bar } ]
arguments = [ 1, 2, 3, { foo: :bar } ]
result = arguments.extract_last_argument_options
assert_equal [ [ 1, 2, 3 ], { :foo => :bar } ], result
assert_equal [ [ 1, 2, 3 ], { foo: :bar } ], result
assert_not_same arguments, result.first
assert_not_same arguments.last, result.last
end
Expand Down
16 changes: 8 additions & 8 deletions tests/file_binary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class TinsFileBinaryTest < Test::Unit::TestCase
def test_ascii_buffer_size
write_file do |file|
file.write "A" * 10 + "\x00"
assert_equal true, file.ascii?(:buffer_size => 10)
assert_equal true, File.ascii?(file.path, :buffer_size => 10)
assert_equal false, file.binary?(:buffer_size => 10)
assert_equal false, File.binary?(file.path, :buffer_size => 10)
assert_equal true, file.ascii?(buffer_size: 10)
assert_equal true, File.ascii?(file.path, buffer_size: 10)
assert_equal false, file.binary?(buffer_size: 10)
assert_equal false, File.binary?(file.path, buffer_size: 10)
end
end

Expand All @@ -27,10 +27,10 @@ def test_binary
def test_ascii_offset
write_file do |file|
file.write "\x01" * 31 + "A" * 70
assert_equal false, file.binary?(:offset => 1)
assert_equal false, File.binary?(file.path, :offset => 1)
assert_equal true, file.ascii?(:offset => 1)
assert_equal true, File.ascii?(file.path, :offset => 1)
assert_equal false, file.binary?(offset: 1)
assert_equal false, File.binary?(file.path, offset: 1)
assert_equal true, file.ascii?(offset: 1)
assert_equal true, File.ascii?(file.path, offset: 1)
end
end

Expand Down
18 changes: 9 additions & 9 deletions tests/find_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ def teardown
end

def test_raising_errors
assert_equal [], find(File.join(@work_dir, 'nix'), :raise_errors => false).to_a
assert_equal [], find(File.join(@work_dir, 'nix'), raise_errors: false).to_a
assert_equal [], find(File.join(@work_dir, 'nix')).to_a
assert_raise(Errno::ENOENT) do
find(File.join(@work_dir, 'nix'), :raise_errors => true).to_a
find(File.join(@work_dir, 'nix'), raise_errors: true).to_a
end
end

def test_showing_hidden
touch file = File.join(@work_dir, '.foo')
assert_equal [ @work_dir ], find(@work_dir, :show_hidden => false).to_a
assert_equal [ @work_dir ], find(@work_dir, show_hidden: false).to_a
assert_equal [ @work_dir, file ], find(@work_dir).to_a
assert_equal [ @work_dir, file ], find(@work_dir, :show_hidden => true).to_a
assert_equal [ @work_dir, file ], find(@work_dir, show_hidden: true).to_a
end

def test_check_directory_without_access
Expand All @@ -42,10 +42,10 @@ def test_check_directory_without_access
mkdir_p directory2 = File.join(directory1, 'bar')
touch file = File.join(directory2, 'file')
chmod 0, directory2
assert_equal [ @work_dir, directory1, directory2 ], find(@work_dir, :raise_errors => false).to_a
assert_equal [ @work_dir, directory1, directory2 ], find(@work_dir, raise_errors: false).to_a
assert_equal [ @work_dir, directory1, directory2 ], find(@work_dir).to_a
assert_raise(Errno::EACCES) do
find(@work_dir, :raise_errors => true).to_a
find(@work_dir, raise_errors: true).to_a
end
ensure
File.exist?(directory2) and chmod 0777, directory2
Expand All @@ -58,9 +58,9 @@ def test_follow_symlinks
mkdir_p directory3 = File.join(directory1, 'bar')
touch file = File.join(directory3, 'foo')
ln_s directory3, link = File.join(directory2, 'baz')
assert_equal [ directory2, link ], find(directory2, :follow_symlinks => false).to_a
assert_equal [ directory2, link ], find(directory2, follow_symlinks: false).to_a
assert_equal [ directory2, link, linked = File.join(link, 'foo') ], find(directory2).to_a
assert_equal [ directory2, link, linked ], find(directory2, :follow_symlinks => true).to_a
assert_equal [ directory2, link, linked ], find(directory2, follow_symlinks: true).to_a
end

def test_path_file
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_path_extension
end

def test_suffix
finder = Tins::Find::Finder.new(:suffix => 'bar')
finder = Tins::Find::Finder.new(suffix: 'bar')
f = File.open(fpath = File.join(@work_dir, 'foo.bar'), 'w')
g = File.open(gpath = File.join(@work_dir, 'foo.baz'), 'w')
fpath = finder.prepare_path fpath
Expand Down
4 changes: 2 additions & 2 deletions tests/from_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def bar
class DerivedKlass < MyKlass
extend Tins::FromModule

include from :module => MyIncludedModule, :methods => [ :foo ]
include from module: MyIncludedModule, methods: [ :foo ]
end

module MyModule
Expand All @@ -44,7 +44,7 @@ class AnotherDerivedKlass

extend Tins::FromModule

include from :module => MyIncludedModule, :methods => :foo
include from module: MyIncludedModule, methods: :foo
end

def test_derived_klass
Expand Down
10 changes: 5 additions & 5 deletions tests/null_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_null
end

def test_null_plus
assert_equal 1, null_plus(:value => 1)
assert_equal 1, NullPlus(:value => 1)
assert_kind_of Tins::NullPlus, null_plus(:value => nil)
assert_kind_of Tins::NullPlus, NullPlus(:value => nil)
assert_equal 1, null_plus(value: 1)
assert_equal 1, NullPlus(value: 1)
assert_kind_of Tins::NullPlus, null_plus(value: nil)
assert_kind_of Tins::NullPlus, NullPlus(value: nil)
assert_kind_of Tins::NullPlus, null_plus
assert_kind_of Tins::NullPlus, NullPlus()
assert_kind_of Tins::NullPlus, null_plus.foo
Expand All @@ -48,7 +48,7 @@ def test_null_plus
def foo
1 / 0
rescue => e
null_plus(:error => e)
null_plus(error: e)
end

def test_null_plus_caller_and_misc
Expand Down
16 changes: 8 additions & 8 deletions tests/token_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
module Tins
class TokenTest < Test::Unit::TestCase
def test_token_failures
assert_raises(ArgumentError) { Tins::Token.new(:bits => 0) }
assert_raises(ArgumentError) { Tins::Token.new(:length => 0) }
assert_raises(ArgumentError) { Tins::Token.new(:alphabet => %w[0]) }
assert_raises(ArgumentError) { Tins::Token.new(bits: 0) }
assert_raises(ArgumentError) { Tins::Token.new(length: 0) }
assert_raises(ArgumentError) { Tins::Token.new(alphabet: %w[0]) }
end

def test_token_for_length
token = Tins::Token.new(:length => 22)
token = Tins::Token.new(length: 22)
assert_equal 22, token.length
assert_equal 130, token.bits
end

def test_token_for_bits
token = Tins::Token.new(:bits => 128)
token = Tins::Token.new(bits: 128)
assert_equal 22, token.length
# can differ from bits argument depending on alphabet:
assert_equal 130, token.bits
end

def test_alphabet
token = Tins::Token.new(:alphabet => %w[0 1])
token = Tins::Token.new(alphabet: %w[0 1])
assert_equal 128, token.length
assert_equal 128, token.bits
token = Tins::Token.new(:alphabet => %w[0 1 2 3])
token = Tins::Token.new(alphabet: %w[0 1 2 3])
assert_equal 64, token.length
assert_equal 128, token.bits
token = Tins::Token.new(:length => 128, :alphabet => %w[0 1 2 3])
token = Tins::Token.new(length: 128, alphabet: %w[0 1 2 3])
assert_equal 128, token.length
assert_equal 256, token.bits
end
Expand Down
Loading

1 comment on commit 9ebb625

@perlun
Copy link

@perlun perlun commented on 9ebb625 Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming in late here, but I just noted this change since this means that tins 1.7+ are uninstallable on older JRubies (1.7 which we are still not fully migrated away from).

The funny thing is that the new Hash syntax being used here is actually not Ruby 2.0, but 1.9. 😆 So this could probably be changed to require 1.9 and newer...

Please sign in to comment.