Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:51+00:00 2026-05-27T07:32:51+00:00

I have a class defined in a gem by Diff::LCS and I want to

  • 0

I have a class defined in a gem by

Diff::LCS

and I want to add some methods to it, so I figured I would extend it.

Now, I’ve extended object before just by defining:
class Object in object.rb (in my lib/ folder in my rails project)

now, my file where I do

class Diff::LCS (in attempt to extend it)
is called diff_lcs.rb, again in lib/.

Do I need to match the same folder structure as the gem in order to extend it properly?

How do I extend a Class::SubClass thing?

EDIT: added code
test/unit/diff_lcs_test.rb:

#tests lib/diff_lcs.rb
require "test/unit"
require 'diff/lcs'
require 'diff/lcs/string'
require File.expand_path(File.dirname(__FILE__) + "/../../lib/diff_lcs")
# require '../../lib/diff_lcs.rb'
class DiffLCSTest < Test::Unit::TestCase

  def correctly_display_inlineness
    @source_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit..."
    @new_text = "lorem ipsUm sit [amet]!, COnsectetur adipisicing elit i have no idea what I'm doing..."
    return false
  end
end

lib/diff_lcs.rb:

class Diff::LCS
  REMOVED_OPEN = "{*[}"
  REMOVED_CLOSE = "{]*}"
  ADDED_OPEN = "{*(}"
  ADDE_CLOSE = "{)*}"
  def self.apply_diff_inline(source_text, new_text)
    result = ""
    operations = ["-", "+"]
    diffs = diff(source_text, new_text)


    operations.each do |current_operation|

    end
    return result
  end
end

Error:

> bundle exec ruby test/unit/diff_lcs_test.rb
$ APP_PATH/lib/diff_lcs.rb:1: LCS is not a class (TypeError)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:32:52+00:00Added an answer on May 27, 2026 at 7:32 am

    Do you mean “reopen” the class (instead of extend)? If so – you should be able to do exactly what you’ve just said.

    class Diff::LCS
      def my_new_method
        ...
      end
    end
    

    However – you have to beware of load-order. If the place that you have written the above code is loaded before your original Diff:LCS class is loaded – then you’ll not be reopening, but actually defining the class.

    …ah, just re-read your issue. You’re trying to figure out what to name the file in which you put this. Previously you have depended on rails’ default naming convention (eg Object being in object.rb) but you don’t have to do that. you can actually just call it “whatever_library.rb” as long as you manually load it (using include "whatever_library.rb") in your environment.rb (in Rails2) (or I think application.rb for Rails3).

    If you must use rails default then yes, make a directory called “diff”, and in there, put your code in the “lcs.rb” file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with two methods defined in it. public class Routines {
I have a class defined like this (scheme) : myClass = BaseClass.extend({ method1 :
I have a class defined in a separate file and at some point I
I have a class defined as public class viewGroups extends ListActivity Somewhere in the
I have a class defined as: class Obj { public: int width, height; Obj(int
I have a templated class defined (in part) as template <class T> MyClass {
I have the ViewValue class defined as follows: class ViewValue { private Long id;
We have a class Car defined like this in a car.rb file class Car
I have a template class defined like so: template <class T> class Command {
I have a class that defined a user defined operator for a TCHAR*, like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.