diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2ac373 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig + +# Created by https://www.gitignore.io/api/visualstudiocode,macos +# Edit at https://www.gitignore.io/?templates=visualstudiocode,macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/visualstudiocode,macos + +# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) + diff --git a/README.md b/README.md index d303bdf..98c929b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,36 @@ # Ruby - Function to Swap Array Elements -## Table of Contents +# Table of Contents +- [Information](https://github.com/fussykyloren/ruby-array-swap#information) +- [Status](https://github.com/fussykyloren/ruby-array-swap#status) +- [Instructions](https://github.com/fussykyloren/ruby-array-swap#instructions) ## Information +This function implements a typical swap function for an array. This is not easily accessible in Ruby (to my knowledge) so I made a function for me but am happy to share it with you! +This function is built with Ruby v2.6.5p114. To check your version, run: +``` +ruby -v +``` ## Status +At this time, the project is __*finished*__. ## Instructions +To run these program, Ruby v2.6.3p62 (or a compatible version) will need to be installed. To check the version of ruby you are using, run this command in terminal: +``` +ruby -v +``` +If you do not have ruby installed, follow these [instructions](https://www.ruby-lang.org/en/documentation/installation/). +After ruby is installed, you should clone this repository to a place easily accessible to you using this command in terminal: +``` +git clone https://github.com/fussykyloren/ruby-array-swap.git +``` +Your github username and password should be requested. If not, don't worry about it. +After the repository is cloned, you will need to change the directory to where the game example is saved. To to use the fibonacci programs, run this command next: +``` +cd [LOCATION_OF_CLONED_REPOSITORY] +``` +Now you can move the ruby file to where you will need to use it! This can be done using this command: +``` +mv [LOCATION_OF_CLONED_REPOSITORY]/swap.rb [LOCATION_TO_MOVE_FILE] +``` +Or if you'd prefer, you can copy the file using this command: +``` +cp [LOCATION_OF_CLONED_REPOSITORY]/swap.rb [LOCATION_TO_MOVE_FILE] +``` diff --git a/swap.rb b/swap.rb new file mode 100644 index 0000000..72528f1 --- /dev/null +++ b/swap.rb @@ -0,0 +1,7 @@ +class Array + def swap!(arr, a, b) + array = arr.dup + array[a], array[b] = array[b], array[a] + array + end +end \ No newline at end of file