Skip to content

Instantly share code, notes, and snippets.

@Githerdone
Last active December 16, 2015 16:29
Show Gist options
  • Select an option

  • Save Githerdone/5463102 to your computer and use it in GitHub Desktop.

Select an option

Save Githerdone/5463102 to your computer and use it in GitHub Desktop.

Revisions

  1. Githerdone revised this gist Apr 25, 2013. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions classarray.rb
    Original file line number Diff line number Diff line change
    @@ -14,18 +14,17 @@ def pad!(min_size, value = nil)
    end

    def pad(min_size, value = nil)
    new_array = []

    if self.count >= min_size
    return new_array << self
    return new_array = self.clone
    else
    new_array = self.clone
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    return new_array
    return new_array
    end
    end
    end
  2. Githerdone revised this gist Apr 25, 2013. 1 changed file with 9 additions and 19 deletions.
    28 changes: 9 additions & 19 deletions classarray.rb
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,10 @@ def pad!(min_size, value = nil)
    else
    size_is = min_size - self.count
    count = 0
    while count < size_is
    self << value
    count += 1
    end
    while count < size_is
    self << value
    count += 1
    end
    return self
    end
    end
    @@ -19,21 +19,11 @@ def pad(min_size, value = nil)
    if self.count >= min_size
    return new_array << self
    else
    if self.count != 0
    new_array << self
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    else
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    return new_array
    end
  3. Githerdone revised this gist Apr 25, 2013. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions classarray.rb
    Original file line number Diff line number Diff line change
    @@ -6,37 +6,37 @@ def pad!(min_size, value = nil)
    size_is = min_size - self.count
    count = 0
    while count < size_is
    self << value
    count += 1
    end
    self << value
    count += 1
    end
    return self
    end
    end
    end

    def pad(min_size, value = nil)
    new_array = []
    new_array = []

    if self.count >= min_size
    return new_array << self
    else
    if self.count != 0
    new_array << self
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    else
    new_array << self
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    end
    while count < size_is
    new_array << value
    count += 1
    end
    else
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    end
    return new_array
    end
    end
    end
    end

  4. Githerdone created this gist Apr 25, 2013.
    43 changes: 43 additions & 0 deletions classarray.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    class Array
    def pad!(min_size, value = nil)
    if self.count >= min_size
    return self
    else
    size_is = min_size - self.count
    count = 0
    while count < size_is
    self << value
    count += 1
    end
    return self
    end
    end

    def pad(min_size, value = nil)
    new_array = []

    if self.count >= min_size
    return new_array << self
    else
    if self.count != 0
    new_array << self
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    else
    size_is = min_size - self.count
    count = 0
    while count < size_is
    new_array << value
    count += 1
    end
    end
    return new_array
    end
    end
    end

    [1,2,3].pad!(5, "apple")