Sha256: a1c7e4ed4d06a4173175e21a8c4ea373939aaabbbaf9845f56e4c5d735c93e6a

Contents?: true

Size: 466 Bytes

Versions: 12

Compression:

Stored size: 466 Bytes

Contents

module Bitcoin
  module Ext
    module ArrayExt

      refine Array do

        # resize array content with +initial_value+.
        # expect to behave like vec#resize in c++.
        def resize!(new_size, initial_value = 0)
          if size < new_size
            (new_size - size).times{self.<< initial_value}
          elsif size > new_size
            (size - new_size).times{delete_at(-1)}
          end
          self
        end

      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bitcoinrb-1.7.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.6.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.5.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.4.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.3.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.2.1 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.2.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.1.1 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.1.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-1.0.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-0.9.0 lib/bitcoin/ext/array_ext.rb
bitcoinrb-0.8.0 lib/bitcoin/ext/array_ext.rb