How to use another gem dir in addition to 'lib' [closed] - ruby

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've created a Ruby gem with the traditional 'lib' structure, but I also have another directory, say 'more' at the same level as 'lib'. However I cannot seem to access any of the methods in the 'more/*.rb' files. Can anyone tell me what needs to be done?
PS - I know from /Shopify/Liquid that they have a similar situation with 'lib' and 'performance' dirs, and there is a 'performance/shopify/liquid.rb' file and also a 'lib/performance' dir but for the life of me I cannot figure out how all that fits together. If I could resolve that then I think it would also be applicable to my solution.

From liquid's gemspec:
s.require_path = "lib"
It doesn't look like /performance is used in the gem, it's only for benchmarking and testing.
liquid/lib doesn't appear to have a performance directory. Looks like the word 'performance' is only used in the Rakefile really. Again for testing.
You can do this as well, no magic needed, it's just another directory.
If you want to include another directory as a library path, then alter the gemspec require_path value.

Related

Working with monkey patches [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is monkey patching possible in Go as in Ruby?
If so, I have a third party library build, which contains one function called encrypt. Now i want to overwrite the behaviour of the function. Is that possible?
Golang is a compiled language, you'll have to edit the code, recompile and deploy all over again. "monkey patching" isn't possible as if you're talking about changing the software after it is already deployed like ruby. (which is an interpreted language).
But if your concerns are beyond an hotfix and involve adding new code at runtime from external source, you might want to have a look at go plugins.
here's a nice medium post about it.
I'm not big on ruby so to make sure we are on the same page: my understanding is that monkey patching allows you to change the underlying behaviours (methods) attached to a given type at runtime.
In go this would be a big fat no no, probably should be in ruby too for the most part :)
Types are concrete in go, everything has to know what it is dealing with at compile time. It's difficult to propose a solution without a clearer understanding of the end goal, can you provide a more concrete example?

What does gem mean? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am struggling with the concept gem. What does it mean? On jumpstart tutorial I read this
Steve Klabnik, an instructor for Jumpstart, created the sunlight-congress gem.
http://tutorials.jumpstartlab.com/projects/eventmanager.html
What he really did? Did he created the website? Did he created a gem for a website that is already existed?
What do you do when you say
gem 'sunlight-congress'
Please Make sure I am new to programming and explain it in a simple term. I really thank you for your help
See http://guides.rubygems.org/what-is-a-gem/
a gem is kind of a library in the Ruby world, like a Maven artifact in the java world (namely a jar file with identifier and version information and more)
In Ruby, a gem is nothing but a distributed code packaged as a library created by Ruby developer(s). The idea is to keep a particular functionality of code into a library but Ruby does it more beautifully by letting Ruby developers host it on http://rubygems.org/ and library then can used by others. For more information read: http://guides.rubygems.org/what-is-a-gem/

how to add this github project to use in ruby class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am learning how to use the data structure in ruby.
I found this library on github : https://github.com/kanwei/algorithms/tree/master.
I have created a word_count.rb file locally.
I want to use the library I mentioned, locally in my ruby class file.
The link I mentioned has following project structure :
how can I use this project in class file ?
It is published as a gem (just the page you found does not document that fact): https://rubygems.org/gems/algorithms
So if you have a Gemfile in your project, add the line:
gem "algorithms", "~> 0.6.1"
Otherwise, run the following command:
gem install algorithms
and use it like you would any other gem, with
require 'algorithms'
in one of your source files.
require 'algorithms'
include Containers
http://kanwei.github.io/algorithms/

extending a gem's functionality for my local copy [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I use the webdriver-user-agent to resize an automated browser easily, and it has user agents and window sizes configurable in a YAML file. I want to add to the YAML file, and I'm wondering what the best way to do this is. I may have additions that only I'll want to use, so I'm ruling out a pull request on Github, and I don't want to add it under the gem's lib directory, because then I will lose my work when I upgrade the gem.
What's the best way to add additional code to a gem?
Unfortunately, you're talking about adding configuration to the gem, which is less easy than adding code, but still doable.
You're going to monkeypatch whatever it is that the gem uses to load its YAML configuration to instead load the configuration of your choosing. Looking at the source you can see that the YAML is being loaded by #devices and the filename comes from #devices_file. Fortunately for us (though not so much for performance), the loaded YAML isn't cached so just replacing #devices_file will do what you want:
require 'webdriver-user-agent'
module Webdriver
module UserAgent
module Devices
def devices_file
File.expand_path("../my-devices.yml", __FILE__)
end
end
end
end
This will look for a file called my-devices.yml in the same directory as the file the above code is in (like your spec_helper.rb or whatnot) - adjust appropriately.

"Application must run" requirement for Ruby assignment, create gem? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
EDIT: In short, what do I need to do to create a running application in Ruby, do I need to create a gem?
ORIGINAL QUESTION THAT SUCKED:
I've never taken any programming classes, or had assignments before so I'm asking this question in hopes this is clear to someone who has had many programming assignments before.
Basically the instructions state, "The Application must Run."
The instructions on the assignment uploader state that no executable files should be uploaded and the application should be put into a .zip.
For a second I thought I'd just create the app code locally, zip all the files, and upload them, but now I'm second guessing that. It seems like I should create a gem out of my application and then the readme that would be uploaded would instruct them to just install the gem?
Am I on the right track here? I suppose my question can be stated as, I need to create a ruby application that will run, is the best way to do that by creating a gem? Or am I completely over thinking this?
Thank you very much.
The most likely thing is that it means this:
The application must run via executing the command ruby myapp.rb
So it "must run" when you pass the filename of you code to the ruby executable.
Anything else wouldn't make much sense. If you are required to make a gem, that would likely have been explicitly clear. But you should clarify this with your instructor, as there isn't a lot to go on here.

Resources